By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,609 Members | 3,812 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,609 IT Pros & Developers. It's quick & easy.

How to save datagridview data to a sql table?

P: 347
I have a form that shows users data from a sql query. What I want to be able to do is when users make a change, they press a save button, the edited/changed data is saved to a new table and then the window is closed. I've looked for several tutorials for this. Can anyone give me an example of a good tutorial or a code example?

My database that the user would be saving to is called exceptionsedit.

The code I have this far is this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles saveButton.Click
  2.         Dim sql As String = "Insert * Into ExceptionsEdit"
  3.         Dim oCmd As System.Data.SqlClient.SqlCommand
  4.         Dim oDr As System.Data.SqlClient.SqlDataReader
  5.         oCmd = New System.Data.SqlClient.SqlCommand
  6.         Try
  7.             With oCmd
  8.                 .Connection = New System.Data.SqlClient.SqlConnection("Initial Catalog=mdr;Data Source=xxxxx;uid=xxxxx;password=xxxxx")
  9.                 .Connection.Open()
  10.                 .CommandType = CommandType.Text
  11.                 oDr = .ExecuteReader()
  12.             End With
  13.             oDr.Close()
  14.             oCmd.Connection.Close()
  15.         Catch ex As Exception
  16.             MessageBox.Show(ex.Message)
  17.             oCmd.Connection.Close()
  18.         End Try
  19.         Close()
  20.         saveButton.Enabled = False
  21.     End Sub
But from how I understand how datagridviews work, that the user can edit in the form without having to click on save.
Jan 24 '11 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.