using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;
AttachDBFilename=|DataDirectory|\Database1.mdf;integrated Security=True;User instance=True"))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "select * from Nub where name==@user";
cmd.Parameters.Add(new SqlParameter("name", user));
using(SqlDataReader reader = cmd.ExecuteReader())
{
if (reader.Read())
{
string dbpwd = reader.GetString(reader.GetOrdinal("password"));
MessageBox.Show(pwd);
}
}
}
}
MessageBox.Show("打开数据库连接成功");
代码没有任何报错提示,不晓得错在哪。 |