Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. VB.NET MYSQL SAVE DATAGRIDVIEW VALUES TO DATABASE

VB.NET MYSQL SAVE DATAGRIDVIEW VALUES TO DATABASE

Scheduled Pinned Locked Moved Database
databasehelpcsharpmysql
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KipkoechE
    wrote on last edited by
    #1

    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

    L M 2 Replies Last reply
    0
    • K KipkoechE

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      At which point do you get that error?

      K 1 Reply Last reply
      0
      • K KipkoechE

        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

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • L Lost User

          At which point do you get that error?

          K Offline
          K Offline
          KipkoechE
          wrote on last edited by
          #4

          the error is found at dt = ds.Tables("subject1")

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups