dr = cmd.ExecuteReader();怎么一直抛出异常
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Da...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace _0602
{
public partial class FrmDengLu : Form
{
public FrmDengLu()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
this.textBox1.Clear();
this.textBox2.Clear(); this.textBox1.Focus();
}
private void button3_Click(object sender, EventArgs e)
{
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection conn = null;
SqlCommand cmd = null;
SqlDataReader dr = null;
string sql = "Data Source=.\\sqlexpress;Initial Catalog=0602;Integrated Security=True;Pooling=False";
string s = "select * from tb_users where Name='" + this.textBox1.Text + "',Pwd='" + this.textBox2.Text + "'";
conn = new SqlConnection(sql);
cmd = new SqlCommand(s,conn);
conn.Open();
dr = cmd.ExecuteReader();
if (dr.Read())
{
this.DialogResult = DialogResult.OK;
}
dr.Close();
conn.Close(); 展开
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace _0602
{
public partial class FrmDengLu : Form
{
public FrmDengLu()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
this.textBox1.Clear();
this.textBox2.Clear(); this.textBox1.Focus();
}
private void button3_Click(object sender, EventArgs e)
{
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection conn = null;
SqlCommand cmd = null;
SqlDataReader dr = null;
string sql = "Data Source=.\\sqlexpress;Initial Catalog=0602;Integrated Security=True;Pooling=False";
string s = "select * from tb_users where Name='" + this.textBox1.Text + "',Pwd='" + this.textBox2.Text + "'";
conn = new SqlConnection(sql);
cmd = new SqlCommand(s,conn);
conn.Open();
dr = cmd.ExecuteReader();
if (dr.Read())
{
this.DialogResult = DialogResult.OK;
}
dr.Close();
conn.Close(); 展开
2个回答
展开全部
这句错误:string s = "select * from tb_users where Name='" + this.textBox1.Text + "',Pwd='" + this.textBox2.Text + "'";
应该是:string s = "select * from tb_users where Name='" + this.textBox1.Text + "' and Pwd='" + this.textBox2.Text + "'";
应该是:string s = "select * from tb_users where Name='" + this.textBox1.Text + "' and Pwd='" + this.textBox2.Text + "'";
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询