首页 > 代码库 > 执行SQL查询脚本
执行SQL查询脚本
static void Main(string[] args) { Console.WriteLine("输入用户编号:"); string cusernum = Console.ReadLine(); Console.WriteLine("输入用户名:"); string cusername = Console.ReadLine(); string connString = @"Data Source=.; Initial Catalog=lh0216; User ID=sa;pwd=Founder123"; //出了using括号objConnection类会被自动释放 using (SqlConnection objConnection = new SqlConnection(connString)) { objConnection.Open(); using (SqlCommand objCmd = objConnection.CreateCommand()) { objCmd.CommandText = "select * from TBZG where czgbh=‘" + cusernum + "‘" ; using (SqlDataReader objReader = objCmd.ExecuteReader()) { //结果集不为空 if (objReader.Read()) { string cValue = http://www.mamicode.com/objReader.GetString(objReader.GetOrdinal("czgxm")); //检查手工输入的姓名与数据库中查询的名称是否相同 if (cValue =http://www.mamicode.com/= cusername) { Console.WriteLine("你好{0}",cusername); } } else { Console.WriteLine("用户名不存在。"); } } } } Console.ReadKey(); }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。