vb.netgridviewdata-bindingvb.net-2010

Cannot bind to the property or column on the DataSource. vb.net


I have error Cannot bind to the property or column please solution. For notes I use studio visuals 2010. Is there the best solution or recommendation?.

thanks jack

Dim Path As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
Dim cn As String = "provider=Microsoft.Jet.OLEDB.4.0; data source=" & Path & "; Extended Properties=dBase IV"
    Dim WithEvents bmb As BindingManagerBase
    Dim dsTest As New DataSet
Private Sub CreateDataSetfillgridview()
 Try
            Dim query As String = "select EMPLOYEEN,HIREDATE FROM TRIAL"
            Using con As OleDbConnection = New OleDbConnection(cn)
                Using cmd As OleDbCommand = New OleDbCommand(CStr(query), con)
                    Using da As New OleDbDataAdapter(cmd)
                        Dim dt As DataTable = New DataTable()
                         da.Fill(dt)
                        dsTest.Tables.Add(dt)
                    End Using
                End Using
            End Using
            'Bind controls 
            DataGrid1.DataSource = dsTest
'if I comment the code below then a dataset appears as screenshot below
            Me.TextBox1.DataBindings.Add("Text", dsTest, "EMPLOYEEN")
            Dim MyBinding As New Binding("Value", dsTest, "HIREDATE")
            AddHandler MyBinding.Format, AddressOf dtFormatter
            AddHandler MyBinding.Parse, AddressOf dtParser
            DateTimePicker1.DataBindings.Add(MyBinding)

            'Force a Refresh of bound controls
            bmb = Me.BindingContext(dsTest, "TRIAL")
            bmb.Position = bmb.Count
            bmb.Position = 0
        Catch myerror As OleDbException
            MessageBox.Show("Error: " & myerror.Message)
        Finally
        End Try
    End Sub

Cannot bind to the property or column Value cannot be null Parameter name dataTable VIEW DATA datagrid not load row datagrid load row when clicked Cannot bind to the property or column EMPLOYEEN on the DataSource.


Solution

  • This is all thanks to the guide from @CaiusJard

    Dim Path As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
    Dim cn As String = "provider=Microsoft.Jet.OLEDB.4.0; data source=" & Path & "; Extended Properties=dBase IV"
        Dim WithEvents bmb As BindingManagerBase
        Dim dsTest As New DataSet
    Private Sub CreateDataSetfillgridview()
     Try
                Dim query As String = "select EMPLOYEEN,HIREDATE FROM TRIAL"
                Using con As OleDbConnection = New OleDbConnection(cn)
                    Using cmd As OleDbCommand = New OleDbCommand(CStr(query), con)
                        Using da As New OleDbDataAdapter(cmd)
                        Dim dt As DataTable = New DataTable("TRIAL")
                             da.Fill(dt)
                            dsTest.Tables.Add(dt)
                        End Using
                    End Using
                End Using
                'Bind controls 
              DataGrid1.DataSource = dsTest.Tables("TRIAL")
                Me.TextBox1.DataBindings.Add("Text", dsTest, "TRIAL.EMPLOYEEN")
                Dim MyBinding As New Binding("Value", dsTest, "TRIAL.HIREDATE")
                AddHandler MyBinding.Format, AddressOf dtFormatter
                AddHandler MyBinding.Parse, AddressOf dtParser
                DateTimePicker1.DataBindings.Add(MyBinding)
    
                'Force a Refresh of bound controls
                bmb = Me.BindingContext(dsTest, "TRIAL")
                bmb.Position = bmb.Count
                bmb.Position = 0
            Catch myerror As OleDbException
                MessageBox.Show("Error: " & myerror.Message)
            Finally
            End Try
        End Sub