Hi,
I'm having a problem exectuing a simple sql query in vb.net, and am hoping someone can help.
The application i'm building just polls a folder for new files, when a file (usually excel) is put into the folder, my application picks it up, processes it, and then moves the file.
I've managed to execute a stored procedure no problem from my vb.net code, however, when I try to execute an sql statement I get an "unhandled exception" saying that "the specified cast is not valid".
The code I am using is as follows:
Dim mySelectQuery As String = "SELECT * FROM tbl_ImportLog"
Dim myCommand As New SqlCommand(mySelectQuery, SqlConn)
SqlConn.Open()
Dim myReader As SqlDataReader = myCommand.ExecuteReader()
Try
While myReader.Read()
Console.WriteLine((myReader.GetInt32(0).ToString & ", " & myReader.GetString(1)))
End While
Finally
' always call Close when done reading.
myReader.Close()
' always call Close when done reading.
SqlConn.Close()
End Try
Any assistance with this would be much appreciated.
I'm having a problem exectuing a simple sql query in vb.net, and am hoping someone can help.
The application i'm building just polls a folder for new files, when a file (usually excel) is put into the folder, my application picks it up, processes it, and then moves the file.
I've managed to execute a stored procedure no problem from my vb.net code, however, when I try to execute an sql statement I get an "unhandled exception" saying that "the specified cast is not valid".
The code I am using is as follows:
Dim mySelectQuery As String = "SELECT * FROM tbl_ImportLog"
Dim myCommand As New SqlCommand(mySelectQuery, SqlConn)
SqlConn.Open()
Dim myReader As SqlDataReader = myCommand.ExecuteReader()
Try
While myReader.Read()
Console.WriteLine((myReader.GetInt32(0).ToString & ", " & myReader.GetString(1)))
End While
Finally
' always call Close when done reading.
myReader.Close()
' always call Close when done reading.
SqlConn.Close()
End Try
Any assistance with this would be much appreciated.