我收到此错误“nvarchar”附近的语法不正确。必须声明标量变量“@”。我正在使用下面提到的代码。这里 SACALOGIN.MDF 是数据库名 admin_login 是表名。用户名和密码是表格列,admin1.aspx 是另一个网页......请帮助,因为它让我很头疼......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Web.Configuration.Common;
using System.Web.Configuration.Internal;
using System.Data.SqlClient;
using System.Data;
using System.Web.Configuration;
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
SqlConnection cn=new SqlConnection();
cn.ConnectionString =
WebConfigurationManager.ConnectionStrings["SACALOGIN.MDF"].ConnectionString;
cn.Open();
string sql="Select * from admin_login where ID=@[ID]";
SqlCommand cmd=new SqlCommand(sql,cn);
cmd.Parameters.AddWithValue("@[User-Name]",txtUserName.Text);
cmd.Parameters.AddWithValue("@Password",txtPWD.Text);
SqlDataReader dr=cmd.ExecuteReader();
bool found=false;
if(dr.Read())
{
found=true;
cn.Close();
if(found)
{
Response.Redirect("admin1.aspx");
}
else
lblMessage.Text="Sorry! Invalid User Id.";
}
}
}