staticvoidMain(string[] args)
{
Console.WriteLine("输入用户编号:");stringcusernum =Console.ReadLine();
Console.WriteLine("输入用户名:");stringcusername =Console.ReadLine();stringconnString =@"Data Source=.; Initial Catalog=lh0216; User ID=sa;pwd=Founder123";//出了using括号objConnection类会被自动释放using(SqlConnection objConnection =newSqlConnection(connString))
{
objConnection.Open();using(SqlCommand objCmd =objConnection.CreateCommand())
{
objCmd.CommandText="select * from TBZG where czgbh='"+ cusernum +"'";using(SqlDataReader objReader =objCmd.ExecuteReader())
{//结果集不为空if(objReader.Read())
{stringcValue = objReader.GetString(objReader.GetOrdinal("czgxm"));//检查手工输入的姓名与数据库中查询的名称是否相同if(cValue ==cusername)
{
Console.WriteLine("你好{0}",cusername);
}
}else{
Console.WriteLine("用户名不存在。");
}
}
}
}
Console.ReadKey();
}