Date problem with MySql

Ukodiak

New member
Joined
Jan 12, 2005
Messages
3
Programming Experience
Beginner
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.
 
Last edited:
.ToShortDateString

Me.TextBox10.DataBindings.Add(New System.Windows.Forms.Binding("text", ds, "help_ticket.tsk_add_dte").ToShortDateString) 'date added
Me.TextBox11.DataBindings.Add(New System.Windows.Forms.Binding("text", ds, "help_ticket.tsk_comp").ToShortDateString) 'date completed
 
Me.TextBox1.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.DsNewPurchaseOrders1, "Purchase Orders.Date"))

This is the line of code I use. The DataSet is DsNewPurchaseOrders1 on the form. It appears identical to your code, so I'm not sure how to help. Someone will solve you problem I am sure.
 
Back
Top