Object reference

D

Dmension

Dmension said:
Here is a snippet of my code. At "SDA.SelectCommand.CommandText = "Select
(*) FROM Badge " I get an error message that says "Additional information:
Object reference not set to an instance of an object"

Any help would be appreciated..



Private Sub btnfill_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnfill.Click

'Dim Waitfrm As New frmPerload

Dim SDA As New SqlDataAdapter

Dim SCN As New SqlConnection

Dim SDS As New DataSet

'Waitfrm.Show()

'System.Threading.Thread.Sleep(5000)

'Waitfrm.Close()

SDS.Clear()

SbarPanel1.Text = "Loading Personnel"

SCN.ConnectionString = ("Persist Security Info=False;User
ID=cic;Password=cic;Initial Catalog=AG30000;Data Source=ENGSQEG246A;")

SCN.Open()

MessageBox.Show("connection is open")

SDA.SelectCommand.CommandText = "Select (*) FROM Badge "

SDA.SelectCommand.Connection = SCN

SDA.Fill(SDS)

lstBoxPersonnel.DataSource = SDS

lstBoxPersonnel.DisplayMember = "Badge"

SbarPanel2.Text = "Number of Records" +
(SDS.Tables(0).Rows.Count.ToString)

'SCN.Close()'

End Sub
 
G

Guest

Jan. 11, 2005

When you create a new dataadapter, it does not create a blank
DA.SelectCommand object. You must create a SqlCommand and then assign it to
the .SelectCommand property, before you can configure the DA's functioning
through the .SelectCommand.Methods. So:

Private Sub btnfill_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnfill.Click

'Dim Waitfrm As New frmPerload

Dim SDA As New SqlDataAdapter

Dim SCN As New SqlConnection

Dim SDS As New DataSet

'Waitfrm.Show()

'System.Threading.Thread.Sleep(5000)

'Waitfrm.Close()

SDS.Clear()

SbarPanel1.Text = "Loading Personnel"

SCN.ConnectionString = ("Persist Security Info=False;User
ID=cic;Password=cic;Initial Catalog=AG30000;Data Source=ENGSQEG246A;")

SCN.Open()

MessageBox.Show("connection is open")
*** DIM selectcom as new sqlcommand
SDA.SelectCommand = selectcom 'Now you can configure it on the
next line
SDA.SelectCommand.CommandText = "Select (*) FROM Badge "

SDA.SelectCommand.Connection = SCN

SDA.Fill(SDS)

lstBoxPersonnel.DataSource = SDS

lstBoxPersonnel.DisplayMember = "Badge"

SbarPanel2.Text = "Number of Records" +
(SDS.Tables(0).Rows.Count.ToString)

'SCN.Close()'

End Sub

I hope this will solve your problem! Have a great day! :)


Joseph MCAD
 
D

Dmension

THanks Joseph,
Minutes after I sent this I noticed that I did not create a SQLcommand
therefore I cound not execute a command string.
 
Top