c#文本框里怎么调用SQL数据库?

对了,还要匹配数据后接着把内容显示在这个文本框里。因为我要编写一个作业,所以请求各位万能的网友帮我解答!

errorTime = errorTime - 1; string username = txtName.Text.Trim(); //取出账号
string pw = txtPwd.Text.Trim(); //取出密码
string constr = "Server=.;DataBase=SU; Integrated Security=True"; //设置连接字符串
SqlConnection mycon = new SqlConnection(constr); //实例化连接对象
mycon.Open();

SqlCommand mycom = mycon.CreateCommand(); //创建SQL命令执行对象
string s1 = "select account,password from register where account='" + username + "' and password='" + pw + "'"; //编写SQL命令
mycom.CommandText = s1; //执行SQL命令
SqlDataAdapter myDA = new SqlDataAdapter(); //实例化数据适配器
myDA.SelectCommand = mycom; //让适配器执行SELECT命令
DataSet myDS = new DataSet(); //实例化结果数据集
int n = myDA.Fill(myDS, "register"); //将结果放入数据适配器,返回元祖个数
if (n != 0) {
if (checkCode.Text == textCheck.Text) {
MessageBox.Show("欢迎使用!"); //登录成功
this.Close();
} else {
MessageBox.Show("验证码填写错误");
textCheck.Text = "";
}
} else
if (errorTime < 3) {
MessageBox.Show("用户名或密码有错。请重新输入!还有" + errorTime.ToString() + "次机会");
txtName.Text = ""; //清空账号
txtPwd.Text = ""; //清空密码?
txtName.Focus(); //光标设置在账号上
} else {
MessageBox.Show("你输入的用户名或密码已达三次? 将退出程序");
this.Close();
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-01-28
没说清楚追问

也就是在文本框里输入账号或密码,然后匹配数据库里的账号和密码,如果错误的话就显示密码错误啊什么的,这总该清楚了吧?

相似回答