0

尝试在我的 vb.net 页面中执行命令时,DataReader 抛出错误消息并且代码抛出错误是:

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()

错误是:'ExecuteReader'不是'string'的成员如何解决这个问题???

4

3 回答 3

2

尝试添加这个:

sql = "select * from jb_jobs where city='Los Angeles' ";
    var sqlCommand = new SqlCommand(sql, connection);
    sqlCommand.Connection.Open();
    var reader = sqlCommand.ExecuteReader();
于 2013-08-02T12:14:58.020 回答
1

添加这个

connection.Open()
Dim cmd as new SqlCommand(sql,connection )      
Dim reader As SqlDataReader = cmd.ExecuteReader()
于 2013-08-02T12:14:49.193 回答
0
Dim cmd As SqlCommand = new SqlCommand ();

cmd=(sql,connection);

cmd.CommandType=CommandType.Text;

Dim reader As SqlDataReader = cmd.ExecuteReader()
于 2013-08-02T12:15:39.300 回答