日期:2014-05-17  浏览次数:20782 次

利用Sqlcommand连接数据库的问题

    private void button1_Click(object sender, EventArgs e)
        {
            SqlCommand s;
            s = new SqlCommand();
            s.Connection = p;
            string str = string.Format("select  * from 用户表  where 用户ID={0} and 用户密码={1}",this.textBox1.Text,this.textBox2.Text);
            s.CommandText = str;
            s.CommandType = CommandType.Text;
            SqlDataReader sdr = s.ExecuteReader();
           // sdr.Read();
            if(sdr.Read())
            {
                MessageBox.Show("登录成功!");
                主窗体 p1 = new 主窗体();
                p1.Show();
            }
            else
            {
                MessageBox.Show("用户名与密码不匹配!");
            }
        }

错误提示:“System.Data.SqlClient.SqlException”类型的未经处理的异常出现在 System.Data.dll 中。

其他信息: 关键字 'and' 附近有语法错误。
求解!!!!
数据库 ,sqlcommand

------解决方案--------------------