Hi:Alex
If you use VisualStudio's Data Adapter Configuration Wizard ,at fourth step,
in advance Item(left button), you can select create Insert,Update,Delete
command
automatically.If you select it ,after you create Data Adapter,in your code
,like this
this.oleDbDeleteCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbUpdateCommand1 = new System.Data.OleDb.OleDbCommand();
this.daMaster.DeleteCommand = this.oleDbDeleteCommand1;
this.daMaster.InsertCommand = this.oleDbInsertCommand1;
this.daMaster.SelectCommand = this.oleDbSelectCommand1;
this.daMaster.UpdateCommand = this.oleDbUpdateCommand1;
this.oleDbDeleteCommand1.CommandText = "DELETE FROM order_master WHERE
(order_no = ?)";
this.oleDbDeleteCommand1.Connection = this.LocalConn;
this.oleDbDeleteCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_order_no",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "order_no", System.Data.DataRowVersion.Original, null));
this.oleDbInsertCommand1.CommandText = "INSERT INTO order_master(ship_to_no,
pad_no, sales_no, company_no, branch, specia" +
"l_information, shipping_instruction, billing_instruction, create_date,
state, up" +
"load, order_no_remote, upload_date) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, " +
"?)";
this.oleDbInsertCommand1.Connection = this.LocalConn;
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("ship_to_no",
System.Data.OleDb.OleDbType.Integer, 0, "ship_to_no"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("pad_no",
System.Data.OleDb.OleDbType.VarWChar, 6, "pad_no"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("sales_no",
System.Data.OleDb.OleDbType.Integer, 0, "sales_no"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("company_no",
System.Data.OleDb.OleDbType.VarWChar, 5, "company_no"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("branch",
System.Data.OleDb.OleDbType.VarWChar, 12, "branch"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("special_information",
System.Data.OleDb.OleDbType.VarWChar, 50, "special_information"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("shipping_instruction",
System.Data.OleDb.OleDbType.VarWChar, 50, "shipping_instruction"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("billing_instruction",
System.Data.OleDb.OleDbType.VarWChar, 50, "billing_instruction"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("create_date",
System.Data.OleDb.OleDbType.DBDate, 0, "create_date"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("state",
System.Data.OleDb.OleDbType.VarWChar, 10, "state"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("upload",
System.Data.OleDb.OleDbType.Boolean, 2, "upload"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("order_no_remote",
System.Data.OleDb.OleDbType.Integer, 0, "order_no_remote"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("upload_date",
System.Data.OleDb.OleDbType.DBDate, 0, "upload_date"));
//
// oleDbSelectCommand1
//
this.oleDbSelectCommand1.CommandText = "SELECT order_no, ship_to_no,
pad_no, sales_no, company_no, branch, special_inform" +
"ation, shipping_instruction, billing_instruction, create_date, state,
upload, or" +
"der_no_remote, upload_date FROM order_master WHERE (state = ?)";
this.oleDbSelectCommand1.Connection = this.LocalConn;
this.oleDbSelectCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("state",
System.Data.OleDb.OleDbType.VarWChar, 10, "state"));
//
// oleDbUpdateCommand1
//
this.oleDbUpdateCommand1.CommandText = @"UPDATE order_master SET
ship_to_no = ?, pad_no = ?, sales_no = ?, company_no = ?, branch = ?,
special_information = ?, shipping_instruction = ?, billing_instruction = ?,
create_date = ?, state = ?, upload = ?, order_no_remote = ?, upload_date = ?
WHERE (order_no = ?)";
this.oleDbUpdateCommand1.Connection = this.LocalConn;
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("ship_to_no",
System.Data.OleDb.OleDbType.Integer, 0, "ship_to_no"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("pad_no",
System.Data.OleDb.OleDbType.VarWChar, 6, "pad_no"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("sales_no",
System.Data.OleDb.OleDbType.Integer, 0, "sales_no"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("company_no",
System.Data.OleDb.OleDbType.VarWChar, 5, "company_no"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("branch",
System.Data.OleDb.OleDbType.VarWChar, 12, "branch"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("special_information",
System.Data.OleDb.OleDbType.VarWChar, 50, "special_information"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("shipping_instruction",
System.Data.OleDb.OleDbType.VarWChar, 50, "shipping_instruction"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("billing_instruction",
System.Data.OleDb.OleDbType.VarWChar, 50, "billing_instruction"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("create_date",
System.Data.OleDb.OleDbType.DBDate, 0, "create_date"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("state",
System.Data.OleDb.OleDbType.VarWChar, 10, "state"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("upload",
System.Data.OleDb.OleDbType.Boolean, 2, "upload"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("order_no_remote",
System.Data.OleDb.OleDbType.Integer, 0, "order_no_remote"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("upload_date",
System.Data.OleDb.OleDbType.DBDate, 0, "upload_date"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_order_no",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "order_no", System.Data.DataRowVersion.Original, null));
These command was creted by VisualStudio, but you can create yours command
manually,is same thing,
after those command, you can define the command text and paramaters ,(like
yours Insert command)
this.oleDbDeleteCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbUpdateCommand1 = new System.Data.OleDb.OleDbCommand();
this.daMaster.DeleteCommand = this.oleDbDeleteCommand1;
this.daMaster.InsertCommand = this.oleDbInsertCommand1;
this.daMaster.SelectCommand = this.oleDbSelectCommand1;
this.daMaster.UpdateCommand = this.oleDbUpdateCommand1;
After you define these command for DataAdaper(daMaster in my code),if you
changed the datatable(AddNewRow,change value,
delete..)when you call Update,system will depend on the
RowState(Added,Modified,Deleted)to search associated command(
Insert,Update,Delete),that's all .
Keep Touch, Have a nice Day!!!