我得到错误的,"这是一个命令,必须先关闭已打开的DataReader。" try
{
SqlConnection con = new SqlConnection(" Data Source=AHSAN-PC\\SQLEXPRESS;Initial Catalog=bank;Integrated Security=SSPI;MultipleActiveResultSets=True;");
con.Open();
//MessageBox.Show("connected");
SqlCommand cmd = new SqlCommand("select * from account",con);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read().Equals(textBox1.Text))
{
MessageBox.Show("sorry duplicate acc no.");
}
else
{
//SqlCommand cmd = new SqlCommand("select * from account",con);
cmd=new SqlCommand("insert into account values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "')", con);
SqlDataReader drr = cmd.ExecuteReader();
drr.Close();
MessageBox.Show("data added");
}
dr.Close();
con.Close();
//MessageBox.Show("data added");
}
catch (Exception ex)
{
MessageBox.Show("error" + ex.Message);
}
请帮助我。我使用的是SQL Server 2005和C#
我给在代码2中的SQL查询,选择和其他insert.as我想,以防止重复帐户号记录在我的应用程序之一。