-
March 28th, 2014, 05:33 AM
#1
VB - Can not update database through DataGridView
I have tried almost everything, and nothing works. I have this code in button event, on the first click datagridview is populated from database, and on the second click database should be updated from datagridview. That last part doesn't work. Just to mention that changes are made in datagridview in between click through mouse click event (click on cell inserts a value).
Code:
Dim ConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=w:\PD_Z.mdb"
Dim SQLString As String = "SELECT * FROM ZARADE"
Dim OleDBConn1 As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection(ConnString)
Dim DataSet1 As New DataSet()
Dim OleDbDataAdapter1 As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter(SQLString, OleDBConn1)
OleDBConn1.Open()
If Button2.Text = "Unos podataka" Then
OleDbDataAdapter1.Fill(DataSet1, "ZARADE")
DataGridView1.DataSource = DataSet1.Tables("ZARADE")
DataGridView1.Columns.Remove(DataGridView1.Columns(0).Name)
DataGridView1.ReadOnly = False
Button2.Text = "ZAVRSI UNOS"
Button2.ForeColor = Color.DarkRed
Button1.Enabled = False
Label4.Text = "Dok je opcija <ZAVRSI UNOS> aktivna, podaci iz tabele se klikom mogu menjati"
Label4.ForeColor = Color.DarkRed
ComboBox1.Enabled = False
Else
Using con = New OleDbConnection(ConnString)
Me.Validate()
OleDbDataAdapter1.Update(DataSet1.Tables("ZARADE"))
DataSet1.AcceptChanges()
End Using
OleDBConn1.Close()
Label4.Text = " "
Label4.ForeColor = Color.Black
'DataGridView1.ReadOnly = True
Button2.ForeColor = Color.Black
Button1.Enabled = True
ComboBox1.Enabled = True
'Dim cb As New OleDbCommandBuilder(OleDbDataAdapter1)
' cb.QuotePrefix = "["
' cb.QuoteSuffix = "]"
' OleDbDataAdapter1.Update(DataSet1.Tables("ZARADE"))
End If
Now I am getting this error : "Value cannot be null, Parameter name : dataTable"
-
March 28th, 2014, 05:50 AM
#2
Re: VB - Can not update database through DataGridView
testDGV.rar
Here is the sample project.
-
March 28th, 2014, 03:25 PM
#3
Re: VB - Can not update database through DataGridView
Always use [code][/code] tags when posting code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|