日期:2014-05-18 浏览次数:21319 次
SqlConnection myCon2 = new SqlConnection(); myCon2.ConnectionString = "Persist Security Info=False;User id=sa;pwd=111111;database=message;server=(local)"; myCon2.Open(); Console.WriteLine("请输入员工编号:"); string user_id = Console.ReadLine(); SqlDataAdapter adp = new SqlDataAdapter(); DataTable dt = myCon2.GetSchema(); try { SqlCommand cmd = new SqlCommand("select * from user_id" , myCon2); cmd.ExecuteNonQuery(); } catch (SqlException ex) { switch (ex.Number) { case 1146: Console.WriteLine("无此表,创建表"); string mySelectQuery="CREATE TABLE user_id(usermessage VARCHAR(MAX))"; SqlCommand cmd = new SqlCommand(mySelectQuery, myCon2); cmd.ExecuteNonQuery(); Console.Read(); break; default: break; } }