问题描述
- 大神,看看那出错了,说user有语法错误
-
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = null;
try
{
con = new SqlConnection(
"Data Source=llll-PC;Initial Catalog=yonghu;User ID=sa;Password=123");string sql = "select * from Table_1 where Table_1.user=@name and Table_1.pwd=@pwd"; SqlCommand cmd = new SqlCommand(sql, con); cmd.Parameters.AddWithValue("@name", textBox1.Text); cmd.Parameters.AddWithValue("@pwd", textBox2.Text); con.Open(); cmd.Connection = con; SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); if (textBox1.Text=="llll"&&textBox2.Text=="123") { MessageBox.Show("成功!"); Form3 f3 = new Form3(); f3.Show(); } else { MessageBox.Show("失败!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { con.Close(); } }
解决方案
放到你的数据库环境中执行可以吗?
解决方案二:
数据库里有这个字段吗,,
时间: 2024-11-01 07:15:52