救命!数据库Update和Insert的问题!
我想在数据库里Insert或者Update一个记录,但弄了很久都不行。我的代码如下:
this.oleDbSelectCmd.CommandText = "SELECT *";
this.oleDbSelectCmd.CommandText += " FROM Customer";
this.oleDbDAdapter.Fill( ds, "Customer" );
Object[] oValue = new Object[6];
oValue[0] = (Object)strName;
oValue[1] = (Object)strPsw;
oValue[2] = (Object)strEmail;
oValue[3] = (Object)strPhone;
oValue[4] = (Object)strAddress;
oValue[5] = (Object)strPassport;
ds.Tables["Customer"].Rows.Add( oValue );
this.oleDBConn.Open();
this.oleDbDAdapter.Update( ds.Tables["Customer"] );
this.oleDBConn.Close();
这是把一个Customer的表拿出来,然后加入我自己需要的行,再插回去的。但执行到Update的那一步就死了!
另外我还试过用设置oleDbDAdapter.InsertCommand,然后在InsertCommand里写入SQL,但也不行!代码如下:
this.oleDbDAdapter.InsertCommand = this.oleDbInsertCmd;
this.oleDbInsertCmd.Connection = this.oleDBConn;
.
.
.
this.oleDbInsertCmd.CommandText = "INSERT INTO Customer (C_Address, C_EMail, C_Name, C_Passport, C_Password, C_Phone) VALUES ('134', '14', 'David99', '2341', '111', '234')";
this.oleDBConn.Open();
this.oleDbDAdapter.InsertCommand.ExecuteNonQuery();
this.oleDBConn.Close();