quanquan626 2004年02月16日
查询错误: [Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序
Public msgtext As String
Public txtsql As String
Private Sub Command1_Click()
txtsql = "select * from name1 where name='" & Trim(Text1.Text) & "' and password='" & Trim(Text2.Text) & "'"
Set mrc = ExecuteSQL(txtsql, msgtext)
If mrc.BOF Or mrc.EOF Then
MsgBox "error"
Else
MsgBox "ok"
End If
End Sub

Public Function ConnectString() As String
ConnectionString = "Provider=s;Persist Security Info=False;User ID=sa;Initial Catalog=name;Data Source=YW"
End Function

Public Function ExecuteSQL(ByVal SQL As String, MsgString As String) As ADODB.Recordset
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim sTokens() As String
On Error GoTo ExecuteSQL_Error

sTokens = Split(SQL)

Set cnn = New ADODB.Connection
cnn.Open ConnectString
If InStr("INSERT,DELETE,UPDATE,EXECUTE", UCase$(sTokens(0))) Then
cnn.Execute (SQL)
MsgString = sTokens(0) & " query successful"
Else
Set rst = New ADODB.Recordset
rst.Open Trim$(SQL), cnn, adOpenKeyset, adLockOptimistic
Set ExecuteSQL = rst
MsgString = "查询到" & rst.RecordCount & " 条记录 "
End If
ExecuteSQL_Exit:
Set rst = Nothing
Set cnn = Nothing
Exit Function


ExecuteSQL_Error:
MsgString = "查询错误: " & Err.Description
Resume ExecuteSQL_Exit
End Function

结果调试中 msgtext=“查询错误: [Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序”
请问是那里的问题,是SQL服务器?还是我的代码?
再线等!谢谢!
...全文
25 点赞 收藏 1
写回复
1 条回复

还没有回复,快来抢沙发~

发动态
发帖子

863

社区成员

5.5w+

社区内容

VB 数据库(包含打印,安装,报表)
社区公告
暂无公告