我尝试在类中创建ODBC连接。 这是我的班级代码
Public Class Library
Public Function Seek(ByVal Connection As Odbc.OdbcConnection, ByVal TableName As String, ByVal Field As String, ByVal Index As Long)
Dim LibDS As New DataSet
Dim LibDA As Odbc.OdbcDataAdapter = New Odbc.OdbcDataAdapter("SELECT * FROM " & TableName & " WHERE " & Field & " = " & Index & "", Connection)
Return LibDA.Fill(LibDS, TableName)
End Function
End Class
......这是我的表格代码。
Dim LibDS1 As New DataSet
LIbDS1 = Table.Seek(LibConn, "tblRoles", "UserID", varUserID.UserID)
If LibDS1.Tables(0).Rows(0)("Role").ToString = "member" Then
MsgBox("You are member")
End If
这是我的错误:无法将'System.Int32'类型的对象强制转换为'System.Data.DataSet'。我正在使用VBdotNet2005
提前致谢
答案 0 :(得分:1)
函数返回Integer
值,但您想返回DataSet。
Public Function Seek(ByVal Connection As Odbc.OdbcConnection,
ByVal TableName As String, ByVal Field As String, ByVal Index As Long)
as DataSet
.....
LibDA.Fill(LibDS, TableName)
Return LibDs
End Function
答案 1 :(得分:0)
如果没有看到更多的代码(特别是任何导入等),我对此并不完全确定 - 但我的猜测是Table.Seek
返回一个整数(Int32) - 无法分配到DataSet
。您无法从DataSet
的结果中获得Table.Seek
。