I have the following code:
Public Class Payrollfinal
Private Sub Payrollfinal_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
exportfileButton.Enabled = False
Dim oCmd As System.Data.SqlClient.SqlCommand
Dim oDr As System.Data.SqlClient.SqlDataReader
oCmd = New System.Data.SqlClient.SqlCommand
Dim _CMD As SqlCommand = New SqlCommand
Dim adapter As System.Data.SqlClient.SqlDataAdapter = New System.Data.SqlClient.SqlDataAdapter
Dim ds As New DataSet
Try
adapter.Fill(ds)
With oCmd
.Connection = New System.Data.SqlClient.SqlConnection("Initial Catalog=mdr;Data Source=xxxxx;uid=xxxxx;password=xxxxx")
.Connection.Open()
.CommandType = CommandType.StoredProcedure
.Parameters.AddWithValue("@payperiodstartdate", payperiodstartdate)
.Parameters.AddWithValue("@payperiodenddate", payperiodenddate)
.CommandText = "sp_allsum"
oDr = .ExecuteReader()
oCmd.Connection.Close()
End With
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Try
Catch ex As Exception
MessageBox.Show(ex.Message)
oCmd.Connection.Close()
End Try
exportfileButton.Enabled = True
End Sub
and when I run I'm given the error:
The SelectCommand Property has not been initialized before calling 'Fill'
I was given the following code to correct this problem:
oCmd = cnn.CreateCommand
oCmd.CommandText = "sp_allsum"
adapter.SelectCommand = oCmd
adapter.Fill(ds)
and intellisense is telling me that I need to declare cnn. Can anyone please advise what cnn may be used for?
Thank you
Doug