Click here to Skip to main content
15,885,875 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am trying to update a database table ("projenv") from a DGV.
the variables are also used for the DGV. this code works for another DB and DGV. i only changed the variable names.

i get an error
"Value cannot be null."
ds2.tables shows the DGV tables just fine. dt2 will not accept the dataset.


VB.NET
Public Class Form4
Dim dt2 As DataTable
Dim da2 As MySqlDataAdapter
Dim ds2 As DataSet 
Dim bsource2 As BindingSource = New BindingSource()

    Private Sub BtnHtUpdate_Click(sender As Object, e As EventArgs) Handles BtnHtUpdate.Click
        Dim dt2 As New DataTable
        dt2 = ds2.Tables("projenv") {problem is here}
        DGVEnvHtg.BindingContext(dt2).EndCurrentEdit()
        da2.Update(dt2)
    End Sub

any help would be greatly appreciated.
thanks,

What I have tried:

i have searched google, bing, duckduckgo. i have compared this code with an exact copy that works (variables changed) and cannot figured why it doesn't work.
this is my first time posting a question, i apologize if i didn't follow the proper protocol
Posted
Updated 18-Aug-16 2:52am
v2
Comments
Ds2 is a new dataset so the table inside that will be null. Have you initialized it?
Member 12053677 17-Aug-16 20:36pm    
i am using visual studio and in the error mode i can mouse over the dataset and it shows the DGV table just as it should. mousing over the datatable shows it empty. so the dataset is getting the info but not passing it to the datatable.

Hi,

I think the problem is here(Highlighted),

VB.NET
Private Sub BtnHtUpdate_Click(sender As Object, e As EventArgs) Handles BtnHtUpdate.Click
        Dim dt2 As New DataTable
        dt2 = ds2.Tables("projenv") {problem is here}
        DGVEnvHtg.BindingContext(dt2).EndCurrentEdit()
        da2.Update(dt2)
    End Sub


try
VB.NET
dt2 As New DataTable

instead of
VB.NET
Dim dt2 As New DataTable
 
Share this answer
 
have tried
Dim dt2 As DataTable
Dim dt2 As new DataTable

dt2 As New DataTable - gives an error "expression not a method"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900