| | |
Update Database with Changes made to the DataGridView
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
You should use a Command Builder to update records so that changes made to the dataset can be reflected into the database. Here is some sample code-
VB.NET Syntax (Toggle Plain Text)
Public Class Form1 Dim cn As New Odbc.OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=shreyas; User=root;Password=;") Dim cmd As Odbc.OdbcCommand Dim adp As Odbc.OdbcDataAdapter Dim ds As New DataSet Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing cn.Close() End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' Fill the data grid viewer cn.Open() cmd = New Odbc.OdbcCommand("Select * from trial1", cn) adp = New Odbc.OdbcDataAdapter(cmd) adp.Fill(ds, "trial1") Me.DataGridView1.DataSource = ds Me.DataGridView1.DataMember = "trial1" End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Update records using a Command Builder ' The variable i gives the number of records updated Dim cmdbuilder As New Odbc.OdbcCommandBuilder(adp) Dim i As Integer Try i = adp.Update(ds, "trial1") MsgBox("Records Updated= " & i) Catch ex As Exception MsgBox(ex.Message) End Try End Sub End Class
•
•
Join Date: Feb 2009
Posts: 1
Reputation:
Solved Threads: 0
Hello, thanks for the code. Its almost working, I received this message. can you help me?!
"Dynamic SQL generation for the UpdateCommand is not supported against a SelecCommand that does not return any key column information"
"Dynamic SQL generation for the UpdateCommand is not supported against a SelecCommand that does not return any key column information"
![]() |
Other Threads in the VB.NET Forum
- Previous Thread: How to get HTML Source of web page opened by web browser using vb.net
- Next Thread: problem with sqlConnection object
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2005 2008 access arithmetic array assignment basic binary bing box button buttons center check code combobox component connectionstring convert crystalreport data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dosconsolevb.net dropdownlist editvb.net excel file-dialog firewall folder ftp google hardcopy image images isnumericfuntioncall listview login math memory mobile ms mssqlbackend mysql navigate net networking opacity output peertopeervideostreaming picturebox picturebox1 port print printpreview problemwithinstallation project record reports" save savedialog searchbox serial soap sorting string tcp temp text textbox timer toolbox trim updown upload useraccounts usercontrol vb vb.net vb.netcode vb.nettoolboxvisualbasic2008sidebar vb2008 vbnet view visual visualbasic visualbasic.net visualstudio web wpf






