CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2014
    Posts
    2

    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"

  2. #2
    Join Date
    Mar 2014
    Posts
    2

    Re: VB - Can not update database through DataGridView

    testDGV.rar

    Here is the sample project.

  3. #3
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: VB - Can not update database through DataGridView

    Moved to VB.Net forum
    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
  •  





Click Here to Expand Forum to Full Width

Featured