关于C#密码登录的代码
来源:百度知道 编辑:UC知道 时间:2024/05/31 08:06:49
if (this.textBox1.Text == "")
{
MessageBox.Show("用户名不能为空");
this.textBox1.Focus();
return;
}
else if (this.textBox2.Text == "")
{
MessageBox.Show("密码不能为空");
this.textBox2.Focus();
return;
}
string password = textBox1.Text.ToString();
string name = textBox2.Text.ToString();
string connecitonString = @"uid=;pwd=;database=student;server=2260374555AA411\SQLEXPRESS";
SqlConnection conn = new SqlConnection(connecitonString);
conn.Open;
string str = "select count(*) from mima where name='" + textBox1.Text + "' and key='" + textBox2.Text + "'";
错误在conn.open和conn.close!说是只有call和new等对象表达式可用作语句.
这个问题:conn.Close;
要加括号,conn.Close();
还有个问题是:string connecitonString =@"uid=;pwd=;database=student;server=2260374555AA411\SQLEXPRESS";
这句里的@能否去掉,如果去掉的话有个错误在\S的转义符上,应该怎么该!
可以把@换成英文状态的句号。
加上()还是有错误,exception错误是怎么回事?连接有问题吗?
我把我以前写的代码给你看吧,看了你也就清楚了
string strConn = "Data Source=.;Initial Catalog=JJking;uid=sa;pwd=12345";
SqlConnection sqlConn = new SqlConnection(strConn);
string strEmployee1 = "clean";
string strEmployee2 = "front";
string strEmployee3 = "manager";
string employee = "";
try
{
sqlConn.Open();
string strName = txtName.Text.Trim();
string strPwd = txtPwd.Text.Trim();
if (txtName.Text.Trim() == ""