How do I use a CommandBuilder object to prepare the update commands in my dataset?
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. In the following code, we have created and set the update, insert and delete commands using the SqlCommandBuilder objectC# Version
SqlConnection conn = new SqlConnection("server=FARAZ; database=programmersheaven; 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();
VB.Net Version
Dim conn As New SqlConnection("server=FARAZ; database=programmersheaven; uid=sa; pwd=;")
Dim cmdStr As String
cmdStr = "select * from article"
Dim da As New SqlDataAdapter(cmdStr, conn)
Dim ds As New DataSet
da.Fill(ds, "Article")
Dim cmdBuilder As New SqlCommandBuilder(da)
da.InsertCommand = cmdBuilder.GetInsertCommand()
da.UpdateCommand = cmdBuilder.GetUpdateCommand()
da.DeleteCommand = cmdBuilder.GetDeleteCommand()
Back
Sponsored links
.Net Application Updating
One easy to use component adds safe and reliable updating features. Download today for a free trial.
One easy to use component adds safe and reliable updating features. Download today for a free trial.
BugSplat - Automatic Crash Analysis
Fast online exception analysis. Capture customer crash data online.
Fast online exception analysis. Capture customer crash data online.
.Net Localization Tool Sisulizer
Localize your .Net apps: ResX and assemblies. Database, XML & HTML Help localization. Try Sisulizer!
Localize your .Net apps: ResX and assemblies. Database, XML & HTML Help localization. Try Sisulizer!
CSTSOFT Instrumentation .NET & ActiveX Components
A collection of 13 instrumentation .NET/ActiveX/VCL components including Gauge,Knob,LED,Trend etc.
A collection of 13 instrumentation .NET/ActiveX/VCL components including Gauge,Knob,LED,Trend etc.
Web based bug tracking - AdminiTrack.com
AdminiTrack offers an effective web-based bug tracking system designed for professional software development teams.
AdminiTrack offers an effective web-based bug tracking system designed for professional software development teams.
