我检查了每个参数,仍然无法获得Invalid操作异常 并突出显示代码 da.Fill(ds)。请帮帮我。
连接模块:
Imports System.Data
Imports System.Data.SqlClient
Module Connectionmodule
Public constr As String
Public con As SqlConnection
Public usertype As String
Public Sub myconnection()
constr = "server=KARAN-PC;database=Karan;trusted_connection=yes"
con = New SqlConnection(constr)
con.Open()
End Sub
End Module
登录表格:
导入System.Data Imports System.Data.SqlClient
公共类LoginForm Dim da As SqlDataAdapter Dim ds As DataSet Dim query As String
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
query = "select * from usermaster where username = '" & username.Text & "' and password = '" & password.Text & "'"
da = New SqlDataAdapter(query, con)
ds = New DataSet
da.Fill(ds)
If ds.Tables(0).Rows.Count > 0 Then
usertype = ds.Tables(0).Rows(0).Item(2)
MsgBox(usertype)
MsgBox(usertype)
Else
MsgBox("In Valid user")
End If
Me.Close()
End Sub
Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
Me.Close()
End Sub
结束班