我一直在查看下面的代码,天知道有多久了,我似乎找不到问题所在。我看到的与所述错误有关的大多数讨论都表明来源来自参数的拼写错误。但是为什么要撒谎,我看不到任何错字。有人可以告诉我哪里出错了吗?
Dim dt As System.Data.DataTable = New System.Data.DataTable
dim sqlText as string
sqlText = "SELECT id AS privilegeID, " & _
"user_id AS userID, " & _
"module_id AS moduleID, " & _
"can_read AS canRead, " & _
"can_create AS canCreate, " & _
"can_update AS canUpdate, " & _
"can_delete AS canDelete, " & _
"is_deleted AS isDeleted, " & _
"is_active AS isActive " & _
"FROM base_user_privilege " & _
"WHERE " & _
"user_id=@userID AND " & _
"is_deleted=@isDeleted AND " & _
"is_active=@isActive"
SetDBCommand(sqlText)
DBCommand.Parameters.AddWithValue("@userID", userID)
DBCommand.Parameters.AddWithValue("@isDeleted", IsDeleted)
DBCommand.Parameters.AddWithValue("@isActive", IsActive)
dt = DBAction(sqlText, DBActionType.DataTable)
setdbcommand (sqltext)旨在建立连接并且它可以工作,所以我认为错误不存在,因为它在其他 select 和 insert 语句上工作。
请协助。
谢谢。
编辑
这是 setdb 命令:
Public Sub SetDBCommand(ByVal sqlString As String)
If DBConnection.State = ConnectionState.Closed Then
DBConnection.Open()
End If
DBCommand = New SQLiteCommand(sqlString, DBConnection)
End Sub
适用于阅读器但不适用于数据表
我已经意识到,使用我的数据连接函数,上述参数在通过DataReader传递时有效,但在通过DataTable传递时不起作用。是否缺少某些东西?参数是否适用于 DataTables?
Public Function DBAction(ByVal sqlText As String, ByVal ActionType As DBActionType) As Object
DBAction = Nothing
Select Case ActionType
Case DBActionType.DataReader
Return DBCommand.ExecuteReader
Case DBActionType.Dataset
Dim MyAdpater As New SQLiteDataAdapter(sqlText, DBConnection)
Dim myDataSet As New System.Data.DataSet
MyAdpater.Fill(myDataSet)
Return myDataSet
Case DBActionType.DataTable
Dim MyAdpater As New SQLiteDataAdapter(sqlText, DBConnection)
Dim MyDataTable As New System.Data.DataTable
MyAdpater.Fill(MyDataTable)
Return MyDataTable
Case DBActionType.executeNonQuery
DBCommand.ExecuteNonQuery()
Case DBActionType.ExecuteScalar
Dim ScalarItem As Object = DBCommand.ExecuteScalar
Return ScalarItem
Case Else
Throw New Exception("Error in DBACTION")
End Select
End Function