C#棘手问题,请大神帮忙
conn.Open();using (SqlCommand cmd = conn.CreateCommand())
{
//用参数化查询方法查询数据库中的数据
= "select (*)from Table_1 where UserName =@UserName";
cmd.Parameters.Add(new SqlParameter("UserName",txtusername));
using (SqlDataReader reader = cmd.ExecuteReader())
{
if (reader.Read())
这个程序跑到红色字体程序时,会出现下面情况:
不存在从对象类型 System.Windows.Forms.TextBox 到已知的托管提供程序本机类型的映射。
这个问题怎么解决??
private void 登陆_Click(object sender, EventArgs e)
{
using (SqlConnection conn = new SqlConnection(@"Server =.\SQLEXPRESS;AttachDBFilename
=C:\Users\Administrator\Desktop\c\登陆界面1\登陆界面\登陆界面\Database1.mdf;
Integrated Security =true;User instance = true"))
//通过这个类连接SQL数据库
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
//用参数化查询方法查询数据库中的数据
= "select (*)from Table_1 where UserName =@UserName";
cmd.Parameters.Add(new SqlParameter("UserName",txtusername));
using (SqlDataReader reader = cmd.ExecuteReader())
{
if (reader.Read())
{
int errortime = reader.GetInt32(reader.GetOrdinal("Errortimer"));
if (errortime > 3)
{
Console.WriteLine("错误次数过多");
return;
}
string dbpassword = reader.GetString(reader.GetOrdinal("Password"));
if (dbpassword == txtpassword.Text)
{
MessageBox.Show("登陆成功");
errortime = 0;
}
else
{
IncErrorTimers();
MessageBox.Show("登陆失败");
}
}
else
{
MessageBox.Show("用户名不存在");
}
}
}
}
}
private void 重置_Click(object sender, EventArgs e)
{
txtusername.Clear();
txtpassword.Clear();
}
}
}
完整程序
[ 本帖最后由 gaopan_2009 于 2012-11-27 17:05 编辑 ]