我得到这个错误'nvarchar'附近的语法不正确。必须声明标量变量“@”。我正在使用下面提到的代码。这里SACALOGIN.MDF是数据库名称admin_login是表名。用户名和密码是表列和admin1.aspx是另一个网页......请帮助,因为它给了我一个很大的头疼.....如何删除错误'nvarchar'附近的语法不正确。必须声明标量变量“@”
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 [email protected][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.";
}
}
}
您使用的访问?然后你必须使用OleDbCommand和相关的类。 Sql *类用于SqlServer。 – 2013-05-06 12:55:26
查询使用参数'@ [ID]'(您可能只需要一个'?'作为位置参数!),但是您提供了另外两个参数。 – 2013-05-06 12:56:40