C#里的SqlDataAdapter执行create table等语句,为什么结果跟踪不到,该怎么解决
C#里的SqlDataAdapter执行create table等语句,为什么结果跟踪不到
C#里的SqlDataAdapter执行create table等语句,为什么结果跟踪不到
我在c#里用SqlDataAdapter执行create table、insert等语句,最后用select获得insert的结果集,fill到datagridview的datasource中,内容显示正常,但在数据库中无法查到新增的表或表中新增的内容,且其他按钮调用该表也失败,为什么呢?正确的执行create table等的做法是怎么样的?
------解决方案--------------------
直接用SqlCommand对象的ExecuteNonQuery()方法执行。
------解决方案--------------------
你应该检查你Create Table的sql语句对不对?
给个创建表的示例
C#里的SqlDataAdapter执行create table等语句,为什么结果跟踪不到
我在c#里用SqlDataAdapter执行create table、insert等语句,最后用select获得insert的结果集,fill到datagridview的datasource中,内容显示正常,但在数据库中无法查到新增的表或表中新增的内容,且其他按钮调用该表也失败,为什么呢?正确的执行create table等的做法是怎么样的?
------解决方案--------------------
直接用SqlCommand对象的ExecuteNonQuery()方法执行。
------解决方案--------------------
你应该检查你Create Table的sql语句对不对?
给个创建表的示例
- C# code
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(); }