473,378 Members | 1,405 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

About SqlCommandBuilder

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();
}
Aug 20 '08 #1
0 1132

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Nick | last post by:
Hi, The SqlCommandBuilder class seems to be able to remember the primary key of a row such that even if I change that key's value, it is still able to update only that row. So I would like to...
4
by: EMW | last post by:
I've posted serveral times to get an answer, but till now still now satisfying answers. Here is my problem: I have filled a datagrid control with the contents of an Excel sheet. Over 3500...
10
by: Hank1234 | last post by:
Can I use one Data Adapter and one Command Builder to update amny tables? Currently in my data adapter I query two tables and fill them into two tables in a data set. When I make a change to a...
5
by: microsoft.private.windows.netserver.setup | last post by:
I have a very strange thing occurring in the program. I have a dataset retrieved from a stored procedure that just select * from a table. I then try to use the SQlCommandBuilder on the dataset,...
4
by: Jim Reynolds | last post by:
Hi, I am using a SqlCommandBuilder to update a Db table via an updated DataSet and SqlAdapter and it doesn't seem to be generating the activity commands from the Select command. Here is a snippet....
9
by: cherishman | last post by:
When I use self-defined database, sometimes the dataadapter can't auto create insertcommand, updatecommand and deletecommand, it just only create selectcommand? But when I use these database such...
0
by: DG | last post by:
I use this code: _adapter = new SqlDataAdapter(selectString, _conn); _adapter.SelectCommand = new SqlCommand(selectString, _conn); _adapter.SelectCommand.Transaction = _trans; _builder = new...
1
by: Tony Johansson | last post by:
Hello! When I use this SqlCommandBuilder will there be created sql command for all three sql statement(update,insert and delete) //Tony
2
by: raulbolanos | last post by:
Hi Pr0's, I have a problem trying to implement the same example from this link: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommandbuilder.aspx But instead of Sql I use...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.