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
CodePudding user response:
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