![]() As you can see, as usual, you create a connection to the database and use it to create the adapter object. Listing 5-54 shows how to use SqlCommandBuilder. You can use OleDbCommand Builder and ODBCCommandBuilder classes in same way. Now you'll see how to use the SqlCommandBuilder in an application. The RefreshSchema method refreshes the database schema. The GetDeleteCommon, GetUpdateCommand, and GetInsertCommand methods return the delete, update, and insert commands in the form of a Command object. The DataAdapter property of a CommonBuilder represents the DataProvider attached to a CommonBuilder object for which automatic SQL statements are generated. SqlCommandBuilder builder = new SqlCommandBuilder(adapter) You pass a DataAdapter as an argument of the CommandBuilder constructor. I'll use OleDbCommandBuilder class in this example.Ĭreating a CommonedBuider object is pretty simply. Once you know how to use OleDbCommandBuilder, you can use SqlCommandBuilder and OdbcCommandBuilder in a similar way. These classes also work in pretty similar fashion. The OleDbCommandBuilder, SqlCommonBuilder, and OdbcCommandBuilder classes represent the CommonBuilder object in the OleDb, Sql, and ODBC data providers. ![]() ![]() Similar to other objects, each data provider has a command builder class. In other words, the CommandBuilder helps you to generate update, delete., and insert commands on a single database table for a data adapter. A CommandBuilder object reduces the burden of creating SQL statements for you. Sometimes creating SQL statements could be lengthy job when dealing with many columns in a table. This article has been excerpted from book "A Programmer's Guide to ADO.NET in C#".ĬommandBuilder: Easing the Work of the Programmer ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
March 2023
Categories |