Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting SqlDataAdapter.UpdateCommand to work

Status
Not open for further replies.

stuartd

Programmer
Jan 8, 2001
146
US
I have managed to connect to a remote server DB and retriev a record using SqlDataAdapter.SelectCommand and putting the result into a DataSet.

Now i want to update a table. The code appears to run through with no exceptions, but the DB never shows an update.

Here is the code:
Code:
  string s_conn="[connection string]";

  SqlConnection oConn = new SqlConnection(s_conn);
  oConn.Open ();

  SqlCommand oCmd;
  oCmd = new SqlCommand   ("INSERT into Names(Title,Name) VALUES ('Mr','Bloggs')");
  oCmd.Connection=oConn;

  // Update the data using the DataAdaptor
  SqlDataAdapter oDA = new SqlDataAdapter();
  oDA.UpdateCommand = oCmd;

How can i find what the problem is? Is there some value i can read from the DataAdapter to find out what happened?



SD
 
Found a way of doing it

Code:
  string s_conn="[connection string]";

  SqlConnection oConn = new SqlConnection(s_conn);
  oConn.Open ();

  SqlCommand oCmd;
  oCmd = new SqlCommand   ("INSERT into Names(Title,Name) VALUES ('Mr','Bloggs')");
  oCmd.Connection=oConn;
  [b]int rows=oCmd.ExecuteNonQuery();[/b]

  MessageBox.Show(rows + " records updated");

Using the SqmCommand.ExecuteNonQuery function.

SD
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top