Public Function GET_B(ByVal CampusCode As String) As DataSet
Dim objConn As New SqlConnection(Connection.ConnectionString)
Dim strSQL As String
strSQL = "SELECT BldgCode "
strSQL += "FROM BuildingPublicExt "
strSQL += "WHERE (CampusCode = N'" & "@CampusCode" & "') "
strSQL += "AND (BldgStatusCode = N'A') "
strSQL += "ORDER BY BldgCode"
Dim cmd As New SqlCommand(strSQL)
cmd.Parameters.AddWithValue("@CampusCode", CampusCode)
Dim ad As New SqlDataAdapter(cmd, objConn)
Dim ds As New DataSet
ad.Fill(ds, "Result")
Return ds
objConn.Close()
End Function
是" Dim cmd As New SqlCommand(strSQL)
"的格式是正确的..?或者我需要在参数中添加任何连接对象..
答案 0 :(得分:0)
您需要将SqlConnection
对象作为第二个参数in
构造函数of
SqlCommand`传递。
Dim cmd As New SqlCommand(strSQL,objConn);
如果您执行此操作,则无需在SqlConnection
的{{1}}中传递constructor
个对象。
SqlDataAdapter
如果您在Dim ad As New SqlDataAdapter(cmd); //Remove objConn from here.
中传递SqlConnection
对象,则第一次评估应该是SqlAdapter constructor
类型,这将是您的查询。