I have a small form which i allow the user to search based on dates and/or select the book from the list.
the export is a function that I call for the date search and the book selection.
the dates search works fine. i use text boxes, but since I am also using a select box for the books, I don't know what to do. I thought about a datareader, but I am not sure how to proceed. with my current code, I get the following error: 'ExecuteReader: Connection property has not been initialized.' so, I know I am really way off in left field. I also tried a hidden text field that will also display the value of the book, but that seemed redundant.
is this possible, or do i need to create 2 separate functions?
===CODE EXTRACT=====
'this is the button for the book selection (which doesn't work)
Protected Sub datesExportButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles datesExportButton.Click
runExportProg()
end sub
'this is the beginning of the function for the excel export, lot of code, so i won't paste it all
function runExportProg()As System.Data.DataTable
Using conn As New SqlConnection("Server=testServer;Initial Catalog=myTestTable;User ID=userxy; Password=password")
'the following will base the export on program name
If programList.SelectedValue.ToString <> "" Then
Dim mySqlCommand As New SqlCommand
Dim myDataReader As SqlDataReader
' mySqlCommand = New SqlCommand("select * from programDealCMS where worksheetID= @worksheetID;", conn)
Dim pullfilesbyProgram As String = "select * from programDealCMS where worksheetID= @worksheetID;"
mySqlCommand.Parameters.Add("@worksheetID", System.Data.SqlDbType.Int)
mySqlCommand.Parameters("@worksheetID").Value = programList.SelectedValue
'programID.Text = "@worksheetID".ToString
conn.Open()
'place reader here??
myDataReader = mySqlCommand.ExecuteReader()
Do While (myDataReader.Read())
programID.Text = myDataReader.Item("worksheetID").ToString()
Loop
'rest of excel data for export
End If
End Using
end function
thanks in advance
the export is a function that I call for the date search and the book selection.
the dates search works fine. i use text boxes, but since I am also using a select box for the books, I don't know what to do. I thought about a datareader, but I am not sure how to proceed. with my current code, I get the following error: 'ExecuteReader: Connection property has not been initialized.' so, I know I am really way off in left field. I also tried a hidden text field that will also display the value of the book, but that seemed redundant.
is this possible, or do i need to create 2 separate functions?
===CODE EXTRACT=====
'this is the button for the book selection (which doesn't work)
Protected Sub datesExportButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles datesExportButton.Click
runExportProg()
end sub
'this is the beginning of the function for the excel export, lot of code, so i won't paste it all
function runExportProg()As System.Data.DataTable
Using conn As New SqlConnection("Server=testServer;Initial Catalog=myTestTable;User ID=userxy; Password=password")
'the following will base the export on program name
If programList.SelectedValue.ToString <> "" Then
Dim mySqlCommand As New SqlCommand
Dim myDataReader As SqlDataReader
' mySqlCommand = New SqlCommand("select * from programDealCMS where worksheetID= @worksheetID;", conn)
Dim pullfilesbyProgram As String = "select * from programDealCMS where worksheetID= @worksheetID;"
mySqlCommand.Parameters.Add("@worksheetID", System.Data.SqlDbType.Int)
mySqlCommand.Parameters("@worksheetID").Value = programList.SelectedValue
'programID.Text = "@worksheetID".ToString
conn.Open()
'place reader here??
myDataReader = mySqlCommand.ExecuteReader()
Do While (myDataReader.Read())
programID.Text = myDataReader.Item("worksheetID").ToString()
Loop
'rest of excel data for export
End If
End Using
end function
thanks in advance