I need help about "MyCommand.ExecuteReader()"
-
:confused: Hi everyone i don't know what happend on this code. I every help page or site, them tell the same code, but in my machine is not working. Please help me on that. The msg error is " An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll " And the line error is " myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection) " Please i need that as soon as possible. :confused: Thank Johnny Lizardo Johnny Lizardo
-
:confused: Hi everyone i don't know what happend on this code. I every help page or site, them tell the same code, but in my machine is not working. Please help me on that. The msg error is " An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll " And the line error is " myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection) " Please i need that as soon as possible. :confused: Thank Johnny Lizardo Johnny Lizardo
We need to know a bit more, like what the rest of the myCommand object is setup with and what the connection object looks like. It would appear that the rest of the command object is not setup with a SELECT statement that is compatible with the ExecuteReader method. Also, how is myReader declared? RageInTheMachine9532
-
We need to know a bit more, like what the rest of the myCommand object is setup with and what the connection object looks like. It would appear that the rest of the command object is not setup with a SELECT statement that is compatible with the ExecuteReader method. Also, how is myReader declared? RageInTheMachine9532
Imports System.Data.SqlClient Module SQL Public sqlSelect As String Public myConnection As New SqlConnection() Public myReader As SqlDataReader myConnection.ConnectionString = "data source=JLZONE\JLZONE;initial catalog=PMC;integrated _ security=SSPI;persist security info=False;workstation id=JLZONE;packet size=4096" myConnection.Open() sqlSelect = "Select * from Users" Dim myCommand As New SqlCommand(sqlSelect, myConnection) myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection) While myReader.Read() Console.WriteLine("myreader record = " & " " & myReader.GetValue(1)) End While myReader.Close() myConnection.Close() myConnection.Dispose() End Function Johnny Lizardo
-
Imports System.Data.SqlClient Module SQL Public sqlSelect As String Public myConnection As New SqlConnection() Public myReader As SqlDataReader myConnection.ConnectionString = "data source=JLZONE\JLZONE;initial catalog=PMC;integrated _ security=SSPI;persist security info=False;workstation id=JLZONE;packet size=4096" myConnection.Open() sqlSelect = "Select * from Users" Dim myCommand As New SqlCommand(sqlSelect, myConnection) myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection) While myReader.Read() Console.WriteLine("myreader record = " & " " & myReader.GetValue(1)) End While myReader.Close() myConnection.Close() myConnection.Dispose() End Function Johnny Lizardo
OK. Everything looks good with your code. Sooooo.... Two possibilities exist that can generate this problem: One is the connection string. Does the database exist? Does is require a username and password to be sent in the connection string? Does it have a real live table called 'Users' or is it a View? Does the Select statement really work? The second is a busted MDAC installation. You might want to try reinstalling MDAC 2.6 SP2 or better. You can pick that up here[^]. RageInTheMachine9532
-
OK. Everything looks good with your code. Sooooo.... Two possibilities exist that can generate this problem: One is the connection string. Does the database exist? Does is require a username and password to be sent in the connection string? Does it have a real live table called 'Users' or is it a View? Does the Select statement really work? The second is a busted MDAC installation. You might want to try reinstalling MDAC 2.6 SP2 or better. You can pick that up here[^]. RageInTheMachine9532