新手求教在c#窗体程序设计完成,运行程序出现当前上下文中不存在文件名txtUserName
private void button1_Click(object sender, EventArgs e){
if (txtUserName.Text.Trim() == "" || txtUserPassword.Text.Trim == "")
{
MessageBox.Show("用户名或密码不能为空!");
txtUserName.Focus();
return;
}
string connString = @"Data Source=windows-PC;Initial Catalog=AddressList;Integrated Security=True";
string sqlStr = string.Format("select count(*) from [User] where UserName='{0}' and Password='{1}'",txtUserName.Text.Trim,txtUserPassword.Text.Trim());
using (SqlConnection conn = new SqlConnection(connString))
{
SqlCommand amd = new SqlCommand(sqlStr, conn);
conn.Open();
int n=Convert.ToInt32(cmd.ExecuteScalar());
if (n == 1)
{
MessageBox.Show("登录成功!");
}
else
{
MessageBox.Show("用户名或密码错误!","错误");
txtUserName.Text = "";
txtUserPassword.Text = "";
txtUserName.Focus();
}