我有一段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
展开
 我来答 举报
百度网友8f4ed2c13
2011-05-04
知道答主
回答量:27
采纳率:0%
帮助的人:9.7万
展开全部
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
更多追问追答
追问
这行那里错了呢
能告诉我怎么改吗
追答
rst.Open sql , Conn, 1, 3, 1  你没把sql 传过去
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式