Updating and Inserting Records in SQL Table

Shaitan00

Well-known member
Joined
Aug 11, 2003
Messages
343
Location
Hell
Given an SQL Query String [strQuery] made to Insert/Update a SQL Table, how would you execute the command in c#?

For the "Select" Query statements it was simple:
System.Data.SqlClient.SqlDataAdapter sqlDA = new System.Data.SqlClient.SqlDataAdapter(strQuery, m_SqlConnection);

However this line is not working for "Insert" and "Update", it does not generate any errors but the SQL Table is not updated.

Note: Connection to the Database has already been established.
 
I think you have to specify the command you want to insert into. For example:

[VB]
System.Data.SqlClient.SqlDataAdapter.SelectCommand(strQuery, m_SqlConnection)

System.Data.SqlClient.SqlDataAdapter.UpdateCommand(strUpdate, m_SqlConnection)
[/VB]

The above lines will setup the adapter, then you acutally have to use the fill and/or upodate methods.
 
Fill and/or Update methods?

I use Fill for the Select Statement when I want to return the Dataset, but what is the Update Method? Do I not just have to send the SQL Command to the SQL Server?

This is where I get lost....


Also not that I do not have the .SelectCommand or .UpdateCommand options. Am I supposed to include something special for those?
 
Last edited by a moderator:
Back
Top