我有一段vb代码 运行时总是错误 哪位好心人士 帮我解答一下 5
PublicFunctionexesql(ByValsqlAsString)AsADODB.Recordsetsql=Trim(sql)Setconn=NewADODB....
Public Function exesql(ByVal sql As String) As ADODB.Recordset
sql = Trim(sql)
Set conn = New ADODB.Connection
Set rst = New ADODB.Recordset
conn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=;Data Source="
conn.Open
rst.ActiveConnection = conn
rst.LockType = adLockOptimistic
rst.CursorType = adOpenKeyset
rst.Open
Set exesql = rst
Set rst = Nothing
Set conn = Nothing
End Function
Private Sub Command1_Click()
Dim rs As New ADODB.Recordset
Dim num As Integer
Dim txtSQL As String
txtSQL = "select * from 学生数据表 where 登录用户名='" & Trim(txtUserName.Text) & " '" & " and 登录密码=' " & Me.TxtPwd.Text & "'"
Set rs = exesql(txtSQL)
num = rs(0)
If IsNull(Me.txtUserName) Then
MsgBox ("请输入用户名!")
ElseIf IsNull(Me.TxtPwd) Then
MsgBox ("请输入登陆密码!")
ElseIf num <> 1 Then
MsgBox ("用户名或密码不正确,请重新输入!")
Else
Me.Visible = False
loginflag = True
系统主界面.Show
End If
End Sub 展开
sql = Trim(sql)
Set conn = New ADODB.Connection
Set rst = New ADODB.Recordset
conn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=;Data Source="
conn.Open
rst.ActiveConnection = conn
rst.LockType = adLockOptimistic
rst.CursorType = adOpenKeyset
rst.Open
Set exesql = rst
Set rst = Nothing
Set conn = Nothing
End Function
Private Sub Command1_Click()
Dim rs As New ADODB.Recordset
Dim num As Integer
Dim txtSQL As String
txtSQL = "select * from 学生数据表 where 登录用户名='" & Trim(txtUserName.Text) & " '" & " and 登录密码=' " & Me.TxtPwd.Text & "'"
Set rs = exesql(txtSQL)
num = rs(0)
If IsNull(Me.txtUserName) Then
MsgBox ("请输入用户名!")
ElseIf IsNull(Me.TxtPwd) Then
MsgBox ("请输入登陆密码!")
ElseIf num <> 1 Then
MsgBox ("用户名或密码不正确,请重新输入!")
Else
Me.Visible = False
loginflag = True
系统主界面.Show
End If
End Sub 展开
展开全部
Public Function exesql(ByVal sql As String) As ADODB.Recordset
sql = Trim(sql)
Set conn = New ADODB.Connection
Set rst = New ADODB.Recordset
conn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=;Data Source="
conn.Open
rst.Open sql , Conn, 1, 3, 1//******************这行
Set exesql = rst
Set rst = Nothing
Set conn = Nothing
End Function
sql = Trim(sql)
Set conn = New ADODB.Connection
Set rst = New ADODB.Recordset
conn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=;Data Source="
conn.Open
rst.Open sql , Conn, 1, 3, 1//******************这行
Set exesql = rst
Set rst = Nothing
Set conn = Nothing
End Function
更多追问追答
追问
这行那里错了呢
能告诉我怎么改吗
追答
rst.Open sql , Conn, 1, 3, 1 你没把sql 传过去
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询