VB.NET MYSQL SAVE DATAGRIDVIEW VALUES TO DATABASE
-
i am trying to save datagridview records to mysql table...But am getting the error: "value cannot be null parameter:datasource" any help private sub Save() Try con = New MySqlConnection(dbPath) sql = "SELECT *FROM shubject1" da = New MySqlDataAdapter(sql, con) con.Open() ds = New DataSet() cmdb = New MySqlCommandBuilder(da) da.Fill(ds, "subject1") bsource.DataSource = ds.Tables("subject1") dgMarksheet.DataSource = bsource Catch ex As Exception MsgBox(ex.Message) End Try end sub Private Sub SaveRecords() Try ds = New DataSet() dt = New DataTable() dt = ds.Tables("subject1") Me.dgMarksheet.BindingContext(dt).EndCurrentEdit() Me.da.Update(dt) MsgBox("Saved", MsgBoxStyle.Information, "Record Changes") Catch ex As Exception MsgBox(ex.Message) Exit Sub End Try End Sub
-
i am trying to save datagridview records to mysql table...But am getting the error: "value cannot be null parameter:datasource" any help private sub Save() Try con = New MySqlConnection(dbPath) sql = "SELECT *FROM shubject1" da = New MySqlDataAdapter(sql, con) con.Open() ds = New DataSet() cmdb = New MySqlCommandBuilder(da) da.Fill(ds, "subject1") bsource.DataSource = ds.Tables("subject1") dgMarksheet.DataSource = bsource Catch ex As Exception MsgBox(ex.Message) End Try end sub Private Sub SaveRecords() Try ds = New DataSet() dt = New DataTable() dt = ds.Tables("subject1") Me.dgMarksheet.BindingContext(dt).EndCurrentEdit() Me.da.Update(dt) MsgBox("Saved", MsgBoxStyle.Information, "Record Changes") Catch ex As Exception MsgBox(ex.Message) Exit Sub End Try End Sub
-
i am trying to save datagridview records to mysql table...But am getting the error: "value cannot be null parameter:datasource" any help private sub Save() Try con = New MySqlConnection(dbPath) sql = "SELECT *FROM shubject1" da = New MySqlDataAdapter(sql, con) con.Open() ds = New DataSet() cmdb = New MySqlCommandBuilder(da) da.Fill(ds, "subject1") bsource.DataSource = ds.Tables("subject1") dgMarksheet.DataSource = bsource Catch ex As Exception MsgBox(ex.Message) End Try end sub Private Sub SaveRecords() Try ds = New DataSet() dt = New DataTable() dt = ds.Tables("subject1") Me.dgMarksheet.BindingContext(dt).EndCurrentEdit() Me.da.Update(dt) MsgBox("Saved", MsgBoxStyle.Information, "Record Changes") Catch ex As Exception MsgBox(ex.Message) Exit Sub End Try End Sub
In your save method you declare a new dataset and then you try and reference a datatable "subject1" in that new, empty dataset. Next time point out where you are getting the error! You need to get the datacontext of the DGV into a dataset before trying to do anything with it. And dataadaptors must have changed since I last used them, the idea that you can throw an entire datatable at it and get it to update the database was not there in my day, a decade ago :-O
Never underestimate the power of human stupidity RAH