You're combining two different methodologies in the way you're trying to update your tables. If you want to use the DataAdapter.Update(), then the easiest thing to do is to use the whole CommandBuilder thing and not "roll your own" Insert statement (although there's nothing wrong with rolling your own, if you do it right). Look at OleDbCommandBuilder in the .NET help for more info about how to use it (I don't have much experience with using the CommandBuilder, since I don't do it that way).
One thing that may be contributing to your problem is that you're creating the parms yourself. The DataAdapter.Update() does that automatically. Check out the .Update() command in the help for more info.
Another thing ... since you're programmatically adding rows (as shown in your sample code), you need to do a newRow.BeginEdit() and .EndEdit() around your changes.
~~Bonnie
>I create an explicit insert command. After I issue dataAdaptor.update() to insert a record to customer table, The last datarow as not the new inserted recoard but it take the 1st record of dataTable. Why?
>
>I check my customer table, data row was inserted correctly.
>
>
>Thanks.
>
>here is my code :
>
>
>Public frmChg()
>{
> string connStr = "Data Source='C:\\S\\BOARD\\BOARD.DBC';Provider='VFPOLEDB.1'";
> string commStr = "Select cusId,name from customer";
>
> daBoard = new OleDbDataAdapter(commStr,connStr);
>
> InitializeCommands();
> dsBoard = new DataSet();
> daBoard.Fill(dsBoard,"customer");
>
>}
>
>private void AddParms(OleDbCommand cmd, params string[] cols)
>{
> foreach (String column in cols)
> {
> cmd.Parameters.Add("?"+column,OleDbType.Char,0,column);
> }
>}
>
>private void InitializeCommands()
>{
> OleDbConnection conn = (OleDbConnection) daBoard.SelectCommand.Connection ;
>
> //Create an explicit update command
> daBoard.InsertCommand = conn.CreateCommand();
> daBoard.InsertCommand.CommandText = "Insert into customer "+
> "(cusId,name) "+
> "Values (?,?)";
> AddParms(daBoard.InsertCommand,"CusId","Name");
>
>}
>
>
>private void btnNew_Click(object sender, System.EventArgs e)
>{
> DataRow newRow = dsBoard.Tables["customer"].NewRow();
> newRow["CusId"] = txtCusNo.Text;
> newRow["name"] = txtName.Text;
>
> dsBoard.Tables["customer"].Rows.Add(newRow);
> daBoard.Update(dsBoard,"customer");
> dsBoard.AcceptChanges();
>}