求大神帮忙看看这这问题
Console.WriteLine("请输入用户名:");
string name=Console.ReadLine();
Console.WriteLine("请输入密码");
string wpassword = Console.ReadLine();
using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDBFilename=|DataDirectory|\Database1.mdf;Integrated Security=True"))
{
conn.Open();
using(SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "select * from User where name='"+name+"'";
using(SqlDataReader reader = cmd.ExecuteReader())
{
if (reader.Read())
{
//用户存在
string password = reader.GetString(reader.GetOrdinal("password"));
if (wpassword == password)
{
Console.WriteLine("登录成功");
}
else
{
Console.WriteLine("密码错误");
}
}
else
{
Console.WriteLine("用户不存在");
}
}
}
}
Console.WriteLine("打开数据库成功");
Console.ReadKey();
}
以上是代码
using(SqlDataReader reader = cmd.ExecuteReader())
在这句话这里总是报错
[解决办法]
select * from [user] where [name]=...
user与name是系统关键字,建议不要作为表名或字段名使用