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

利用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

------解决方案--------------------
友情链接: 爱易网 云虚拟主机技术 云服务器技术 程序设计技术 开发网站 APP开发教程
Copyright © 2013-2026 爱易网页 当前在线:431人  网站在17时15分55秒内访问总人数:232611人 当前 61.99%  粤ICP备18100884号-2