Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Executing an "Insert Into" SQL Script

Status
Not open for further replies.

theomen

Programmer
Jun 2, 2004
158
GB
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.

 
Ignore me, I think I've found the problem (mainly me being a fool)
 
I've now fixed it. Maybe in future I should try not to use "GetInt32()" on a string field

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top