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 SubPublic Function ConnectString() As String
   ConnectionString = "Provider=s;Persist Security Info=False;User ID=sa;Initial Catalog=name;Data Source=YW"
End FunctionPublic 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服务器?还是我的代码?
再线等!谢谢!