//1个button 2个textbox
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
SqlCommand comm=conn.CreateCommand();
comm.CommandText=CommandType.Text.ToString();
if(this.textBox1.Text.Length==0)
{
MessageBox.Show("用户不能为空,请查询后输入");
this.textBox1.Focus();
return;
}
comm.CommandText="select count(*) from paimai where paihao='"+this.textBox1.Text+"'";
conn.Open();
if((int)comm.ExecuteScalar()==0)
/*
第一次点BUTTON后 可以出来MESSAGEBOX 第二次就提示错误
错误提示: 连接已经打开(state=Open)
*/
{
MessageBox.Show("不存在此用户,请检查后重新输入");
this.textBox1.Focus();
return;
}
comm.CommandText="select paihao,mima from paimai where paihao='"+this.textBox1.Text+"'";
SqlDataReader read = comm.ExecuteReader();
if(read.Read())
{
if(this.textBox2.Text==read[0].ToString() && textBox1.Text.Length != 0)
{
MessageBox.Show("登录成功","恭喜",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
else
{
MessageBox.Show("用户" + textBox1.Text + "的密码不正确","密码",MessageBoxButtons.OKCancel,MessageBoxIcon.Warning);
textBox2.Focus();
return;
}
}
conn.Close();
this.textBox1.Text="";
this.textBox2.Text="";
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
SqlCommand comm=conn.CreateCommand();
comm.CommandText=CommandType.Text.ToString();
if(this.textBox1.Text.Length==0)
{
MessageBox.Show("用户不能为空,请查询后输入");
this.textBox1.Focus();
return;
}
comm.CommandText="select count(*) from paimai where paihao='"+this.textBox1.Text+"'";
conn.Open();
if((int)comm.ExecuteScalar()==0)
/*
第一次点BUTTON后 可以出来MESSAGEBOX 第二次就提示错误
错误提示: 连接已经打开(state=Open)
*/
{
MessageBox.Show("不存在此用户,请检查后重新输入");
this.textBox1.Focus();
return;
}
comm.CommandText="select paihao,mima from paimai where paihao='"+this.textBox1.Text+"'";
SqlDataReader read = comm.ExecuteReader();
if(read.Read())
{
if(this.textBox2.Text==read[0].ToString() && textBox1.Text.Length != 0)
{
MessageBox.Show("登录成功","恭喜",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
else
{
MessageBox.Show("用户" + textBox1.Text + "的密码不正确","密码",MessageBoxButtons.OKCancel,MessageBoxIcon.Warning);
textBox2.Focus();
return;
}
}
conn.Close();
this.textBox1.Text="";
this.textBox2.Text="";
解决方案 »
- 强类型的DataSet如何进行主从表的设置?
- 求教一个C# winform 处理cookies的问题@~~
- 页面上使用AJAX后 无法弹出JS提示框
- 怎样修改ListBox选中项的文本
- listbox 数据绑定问题
- 未赋值的局部变量 returnValue;
- [原创]今天用Delphi和C#分别做了一个全国天气预报WSDL(Web Services)的调用例程序(含全部Source)
- 探讨:关于C#把数据导出到Excel的问题?
- datagrid中新增加一个编辑行,,当光标离开gatagrid时,如何将该编辑行存到邦定的数据源中
- 怎样获取文件的属性??
- asp.net如何实现单窗口多页面?
- 我的JS为什么时好时坏,请大家帮忙
this.textBox1.Text="";
this.textBox2.Text="";
没有执行.所以数据库没有关闭.第二次再运行时就会出现连接已经打开(state=Open)
的错误