DataReader尝试在我的vb.net页面中执行命令时抛出错误消息 代码抛出错误是:
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'的成员 如何解决这个???
答案 0 :(得分:2)
尝试添加此内容:
sql = "select * from jb_jobs where city='Los Angeles' ";
var sqlCommand = new SqlCommand(sql, connection);
sqlCommand.Connection.Open();
var reader = sqlCommand.ExecuteReader();
答案 1 :(得分:1)
添加此
connection.Open()
Dim cmd as new SqlCommand(sql,connection )
Dim reader As SqlDataReader = cmd.ExecuteReader()
答案 2 :(得分:0)
Dim cmd As SqlCommand = new SqlCommand ();
cmd=(sql,connection);
cmd.CommandType=CommandType.Text;
Dim reader As SqlDataReader = cmd.ExecuteReader()