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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Insert Update

Status
Not open for further replies.

richself

Technical User
Jun 27, 2005
37
US
I'm looking for good code examples on updating and/or inserting new records into a SQL database. I've written an App for writing to an Acess Database but now am trying the same with SQL and am getting nowhere. I'm working with a Dataset, which I can insert new rows into fine and the changes will display in a datagrid on my form but the changes do not take effect in the SQL table. If I could get an example with just 1 column I could go from there.

Below is the code I use to update the datagrid.

Dim insertcmd As SqlCommand

insertcmd = New SqlCommand("INSERT INTO Test (ShiftID, SupervisorID) VALUES (@ShiftID, @SupervisorID), myConn")

insertcmd.Parameters.Add("@ShiftID", SqlDbType.Char, 10, "ShiftID")
insertcmd.Parameters.Add("@SupervisorID", SqlDbType.Char, 10, "supervisorID")

myDA.InsertCommand = insertcmd

 
Take a look at the Update method of the DataAdapter. This will apply any changes that have been made to the in memory dataset.

It's best to use the DataAdapter's configuration wizard to generate the INSERT, UPDATE and DELETE commands if possible.


Bob Boffin
 
The problem with using the Wizard is I'm using VB.Net 2003 Standard Edition which does not allow you to use a SQL connection through the wizard. I had to make my connection string manually and am having to everything else manually.
 
It's best to use the DataAdapter's configuration wizard to generate the INSERT, UPDATE and DELETE commands if possible.

you must be joking, right?

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top