I am trying to bind data to textboxes and when I try to pull dates from a mysql table I get the following error:
An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll
Additional information: Object reference not set to an instance of an object.
Here is my code:
Public Class Form1
Inherits System.Windows.Forms.Form
Dim conn As MySqlConnection
Dim ds As DataSet
Dim da As MySqlDataAdapter
Private Sub cmdGet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGet.Click
conn = New MySqlConnection
conn.ConnectionString = "server=localhost;" _
& "user id=LBurch;" _
& "password=rover;" _
& "database=helpdesk;" & " allow zero datetime=yes"
Try
'conn.Open()
Dim query As String = "SELECT * from help_ticket"
Dim cmd As New MySqlCommand(query, conn)
da = New MySqlDataAdapter(query, conn)
ds = New DataSet
da.SelectCommand() = cmd
da.Fill(ds, "help_ticket")
Me.TextBox10.DataBindings.Add(New System.Windows.Forms.Binding("text", ds, "help_ticket.tsk_add_dte")) 'date added
Me.TextBox11.DataBindings.Add(New System.Windows.Forms.Binding("text", ds, "help_ticket.tsk_comp")) 'date completed
These 2 textboxes are throwing the error. The rest of my textboxes that do not display dates work fine.
An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll
Additional information: Object reference not set to an instance of an object.
Here is my code:
Public Class Form1
Inherits System.Windows.Forms.Form
Dim conn As MySqlConnection
Dim ds As DataSet
Dim da As MySqlDataAdapter
Private Sub cmdGet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGet.Click
conn = New MySqlConnection
conn.ConnectionString = "server=localhost;" _
& "user id=LBurch;" _
& "password=rover;" _
& "database=helpdesk;" & " allow zero datetime=yes"
Try
'conn.Open()
Dim query As String = "SELECT * from help_ticket"
Dim cmd As New MySqlCommand(query, conn)
da = New MySqlDataAdapter(query, conn)
ds = New DataSet
da.SelectCommand() = cmd
da.Fill(ds, "help_ticket")
Me.TextBox10.DataBindings.Add(New System.Windows.Forms.Binding("text", ds, "help_ticket.tsk_add_dte")) 'date added
Me.TextBox11.DataBindings.Add(New System.Windows.Forms.Binding("text", ds, "help_ticket.tsk_comp")) 'date completed
These 2 textboxes are throwing the error. The rest of my textboxes that do not display dates work fine.
Last edited: