0

DataReader throwing an error message when trying to execute an command in my vb.net page And the code throwing error is:

Dim connectionString As String
Dim connection As SqlConnection
Dim sql As String

connectionString = \\\connection string\\\
connection = New SqlConnection(connectionString)

sql = "select * from jb_jobs where city='Los Angeles' "
connection.Open()
Dim reader As SqlDataReader = sql.ExecuteReader()

And the error is: 'ExecuteReader' is not a member of 'string' How to resolve this???

2
  • 2
    sql is not SqlCommand. You need to create sqlcommand. Commented Aug 2, 2013 at 12:13
  • You probably want to look at SqlCommand objects. Commented Aug 2, 2013 at 12:14

3 Answers 3

2

Try adding this:

sql = "select * from jb_jobs where city='Los Angeles' ";
    var sqlCommand = new SqlCommand(sql, connection);
    sqlCommand.Connection.Open();
    var reader = sqlCommand.ExecuteReader();
Sign up to request clarification or add additional context in comments.

1 Comment

this vb.net you using c#
1

Add this

connection.Open()
Dim cmd as new SqlCommand(sql,connection )      
Dim reader As SqlDataReader = cmd.ExecuteReader()

1 Comment

Single argument constructor expects the text, not the connection.
0
Dim cmd As SqlCommand = new SqlCommand ();

cmd=(sql,connection);

cmd.CommandType=CommandType.Text;

Dim reader As SqlDataReader = cmd.ExecuteReader()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.