private void button1_Click(object sender, EventArgs e)
{
Con.Open();
SqlDataAdapter sda = new SqlDataAdapter("selet count ( * ) from UserTb where UName='" + UNameTb.Text + "'and.UPassword='" + UPassTb.Text + "'", Con);
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows[0][0].ToString() == "1")
{
Shangpin obj = new Shangpin();
obj.Show();
this.Hide();
Con.Close();
}
else
{
MessageBox.Show("用户名或密码错误!!!");
}
Con.Close();
}
单词写错了,将selet
修正成select
,如下图:
你的SQL语句有两个错误:
1、select写成了selet PS:这错误我不是头一回见你犯了,要改掉这个坏习惯。
2、count和()之间不要有空格应写成count(*) 而不是count 空格( * )
示例:
private void button1_Click(object sender, EventArgs e)
{
Con.Open();
SqlDataAdapter sda = new SqlDataAdapter("select count(*) from UserTb where UName='" + UNameTb.Text + "'and.UPassword='" + UPassTb.Text + "'", Con);
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows[0][0].ToString() == "1")
{
Shangpin obj = new Shangpin();
obj.Show();
this.Hide();
Con.Close();
}
else
{
MessageBox.Show("用户名或密码错误!!!");
}
Con.Close();
}