Each data provider has a command builder object that prepares the update, insert and delete commands for you. You can use these (SqlCommandBuilder, OracleCommandBuilder, OleDbCommandBuilder, OdbcCommandBuilder)objects to generate commands automatically using the Select command you specified when defining the data adapter.
The following code has created and set the update, insert and delete commands using the SqlCommandBuilder object.
In C#.NET
SqlConnection conn = new SqlConnection("server=KIRAN; database=dotnet; uid=sa; pwd=;"); string cmdStr = "select * from article"; SqlDataAdapter da = new SqlDataAdapter(cmdStr, conn); DataSet ds = new DataSet(); da.Fill(ds, "Article"); SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(da); da.InsertCommand = cmdBuilder.GetInsertCommand(); da.UpdateCommand = cmdBuilder.GetUpdateCommand(); da.DeleteCommand = cmdBuilder.GetDeleteCommand();
|
No responses found. Be the first to respond and make money from revenue sharing program.
|