sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
Tony Johansson's Avatar

About SqlCommandBuilder


Question posted by: Tony Johansson (Guest) on August 20th, 2008 08:35 AM
Hello!

This small program below works but I have some questions about it.

Below I have a piece of code that update a specific row in the northwind
database.
The class SqlCommandBuilder is used for creating a suitable update,insert or
delete sql command that
match thisAdapter.

If I look at the object thisBuilder in the debugger on for example
UpdateCommand this is null
but the class SqlCommandBuilder should create a suitable update command.

So my first question is why the UpdateCommand for thisBuilder is null ?
My second question is if it's possible to see the update command that
thisBuilder is creating ?

static void Main(string[] args)
{
//Specify SQL Server-specific connection string
SqlConnection thisConnection = new SqlConnection(
@"Server=UHT-DEMO1;Integrated Security=True;" +
"Database=northwind");

//Create DataAdapter object for update and other operations
SqlDataAdapter thisAdapter = new SqlDataAdapter(
"Select CustomerID, CompanyName from Customers",
thisConnection);

//Create CommandBuilder object to build SQl commands
SqlCommandBuilder thisBuilder = new
SqlCommandBuilder(thisAdapter);

//Create DataSet to contain related data tables, rows and
columns
DataSet thisDataSet = new DataSet();

//Fill DataSet using query defined previously for DataAdapter
thisAdapter.Fill(thisDataSet, "Customers");

//Show data before change is made
Console.WriteLine("Name before change: {0}",
thisDataSet.Tables["Customers"].Rows[9]["CompanyName"]);

//Change data in Customers table, row 9, CompanyName column
thisDataSet.Tables["Customers"].Rows[9]["CompanyName"] = "Acme,
Inc.";

//Call Update command to mark change in table
thisAdapter.Update(thisDataSet, "Customers");

Console.WriteLine("Name after change: {0}",
thisDataSet.Tables["Customers"].Rows[9]["CompanyName"]);

thisConnection.Close();

Console.WriteLine("Program finished, Press Enter/Return to
continue");
Console.ReadLine();
}


0 Answers Posted
 
Not the answer you were looking for? Post your question . . .
196,987 members ready to help you find a solution.
Join Bytes.com

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 196,987 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top Community Contributors