日期:2014-05-18 浏览次数:20933 次
SqlConnection conn = new SqlConnection("Data Source=(local);Initial Catalog=MyDatabase;User ID=sa;Password=sa"); conn.Open(); SqlCommand comm = new SqlCommand(); comm.Connection =conn ; string sql = ""; sql = "CREATE TABLE tablename"; sql += "( "; sql += "date_in datetime,"; sql += "user_id int,"; sql += "myuser_name varchar(200)"; sql += ")"; comm.CommandText = sql; SqlParameter parm1 = new SqlParameter("@tablename", SqlDbType.VarChar, 20); parm1.Value = ("tablename"); comm.Parameters.Add(parm1); try { comm.ExecuteNonQuery();//这是执行语句 MessageBox.Show("成功创建表", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { conn.Close(); }