omidrayaneh.68
شنبه 28 اردیبهشت 1392, 15:18 عصر
سلام من سه تا فیلد دارم id,username,password که همه از نوع nvarchar هست اما هنگام reader کرن پیغام خطا میده
متن خطا
Incorrect syntax near the keyword 'user'.
کد ها
public partial class Login : Form
{
static SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirector y|\system_abzar.mdf;integrated security=true;User Instance=True");
//SqlDataAdapter da = new SqlDataAdapter("", con);
DataSet ds = new DataSet();
SqlCommand command = new SqlCommand();
public Login()
{
InitializeComponent();
}
private void enter_Click(object sender, EventArgs e)
{
con.Open();
command.Connection = con;
command.CommandText = "SELECT username,password from user WHERE username=@user AND password=@pass";
command.Parameters.AddWithValue("@user", textBox1.Text);
command.Parameters.AddWithValue("@pass", textBox2.Text);
SqlDataReader Reader;
Reader = command.ExecuteReader();
if (Reader.HasRows == true)
{
MessageBox.Show("ok");con.Close();
}
else
{
MessageBox.Show("no");
con.Close();
}
}
متن خطا
Incorrect syntax near the keyword 'user'.
کد ها
public partial class Login : Form
{
static SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirector y|\system_abzar.mdf;integrated security=true;User Instance=True");
//SqlDataAdapter da = new SqlDataAdapter("", con);
DataSet ds = new DataSet();
SqlCommand command = new SqlCommand();
public Login()
{
InitializeComponent();
}
private void enter_Click(object sender, EventArgs e)
{
con.Open();
command.Connection = con;
command.CommandText = "SELECT username,password from user WHERE username=@user AND password=@pass";
command.Parameters.AddWithValue("@user", textBox1.Text);
command.Parameters.AddWithValue("@pass", textBox2.Text);
SqlDataReader Reader;
Reader = command.ExecuteReader();
if (Reader.HasRows == true)
{
MessageBox.Show("ok");con.Close();
}
else
{
MessageBox.Show("no");
con.Close();
}
}