private void Button1_Click(object sender, System.EventArgs e)
{
OleDbConnection myConnection = new OleDbConnection("Provider=MSDAORA;User ID=test;Password=test;DataSource=test");
string SelectStr="SELECT id.nextval from dual";
OleDbCommand myCommand = new OleDbCommand(SelectStr,myConnection);
this.oleDbInsertCommand1.CommandText = "INSERT INTO TESTHC(MC, ID) VALUES (?, id.nextval)";
this.oleDbInsertCommand1.Connection = this.oleDbConnection1;
this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("MC", System.Data.OleDb.OleDbType.VarChar, 20, "MC"));
this.oleDbDataAdapter1.InsertCommand.Parameters["mc"].Value=this.TextBox1.Text;
this.oleDbDataAdapter1.InsertCommand.Connection.Open();
this.oleDbDataAdapter1.InsertCommand.ExecuteNonQuery();
this.oleDbDataAdapter1.InsertCommand.Connection.Close();
}
上面的程序可以正确运行,但是为什么我没有ExecuteNonQuery()语句,也没有ExecuteReader()语句,SELECT语句也能执行得到id.nextval的值,并且插入testhc表呢?

解决方案 »

  1.   

    this.oleDbDataAdapter1.InsertCommand.ExecuteNonQuery();这句没有了是插入不了的!
      

  2.   

    我想问我是怎么取出id.nextval的值的,并且取出后存在什么对象里了?
      

  3.   

    建议你看看关于
    ado。net的书籍
    应该能明白的
      

  4.   

    我就是看了书才糊涂的,书上说要用ExecuteNonQuery()或ExecuteReader()语句执行,结果放在DATAREADER里,可我什么都没用,也能执行SELECT取出id.nextval的值啊!
      

  5.   

    this.oleDbInsertCommand1.CommandText = "INSERT INTO TESTHC(MC, ID) VALUES (?, id.nextval)";
    this.oleDbInsertCommand1.Connection = this.oleDbConnection1;
    this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("MC", System.Data.OleDb.OleDbType.VarChar, 20, "MC"));
    this.oleDbDataAdapter1.InsertCommand.Parameters["mc"].Value=this.TextBox1.Text;这就是神奇的地方