Code to Update Into my SQL

Code to Update Into my SQL database using the submit button

Page 1 of 1

2 Replies - 2069 Views - Last Post: 23 February 2009 - 10:39 AM Rate Topic: -----

#1 Blue05  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 23-February 09

Code to Update Into my SQL

Post icon  Posted 23 February 2009 - 04:26 AM

Please help me with this code, not sure where I`m going wrong, want this button to submit or save the changes into my database.


Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSubmit.Click

		dbConn = New SqlConnection(connString)
		Dim qryUp = "Update CMScontent.Content[Content] = @Content Where ContentID = @ContentID"
		dbConn = New SqlConnection(connString)
		Dim daUp As SqlDataAdapter = New SqlDataAdapter(qryUp, dbConn)
		Dim dsUp As DataSet = New DataSet()
		Try
			dbConn.Open()
			daUp.Fill(dsUp)
			txtContent.Text = dsUp.Tables(0).Rows(0)("Content").ToString()
		Catch ex As Exception
		End Try

	End Sub



Is This A Good Question/Topic? 0
  • +

Replies To: Code to Update Into my SQL

#2 fatbunny  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 33
  • Joined: 09-February 09

Re: Code to Update Into my SQL

Posted 23 February 2009 - 05:19 AM

the da.fill only works with sql Select statements as far as I know.

the da will have update, insert and delete commands also, so try this





da.updatecommand = "Update CMScontent.Content[Content] = @Content Where ContentID = @ContentID"
da.updatecommand.executenonquery()


Was This Post Helpful? 0
  • +
  • -

#3 XavierMG  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 19
  • Joined: 20-February 09

Re: Code to Update Into my SQL

Posted 23 February 2009 - 10:39 AM

There's a simple way to update your database, if I'm understanding you correctly.

First you just need to add a command builder in your sub routine and it will auto generate the proper command (in this case update).

So once you filled your dataset and are ready to update try this.

(Add these lines to your code)


dim CB as new oledb.commandbuilder(Dataadapter)

'you already have your dataset (which I'll call 'DS') filled so now just update it.

DataAdapter.Update (DS,"Tblname")



This post has been edited by XavierMG: 23 February 2009 - 10:40 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1