查询错误: [Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序

quanquan626 2004-02-16 01:16:29
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服务器?还是我的代码?
再线等!谢谢!
...全文
90 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhangyang1029 2004-09-03
  • 打赏
  • 举报
回复
哦不好意思,我复制错了,哈哈
是这句:
ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=name;Data Source=YW"

好象少了一个password

1,217

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧