vb与sqlserver数据库连接的问题

80酷酷网    80kuku.com

  server|sqlserver|数据|数据库|数据库连接|问题 

最近编一个物资管理系统,用VB6.0+SQLSERVER2000,在编写executesql函数时出错,

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", UCase$(stokens(0))) Then
      cnn.Execute sql
      msgstring = stokens(0) & "query sucessful"
    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
 
Public Function connectstring() As String
connectstring = "filedsn=material.dsn;uid=sa;pwd=sa"
End Function

预编译执行时出现错误,提示子程序或函数未定义,而且光标指向 EXECUTESQL_EXIT,我已经把MICROSOFT ACTIVEX OBJECTS 2.6 LIBRARY 添加了,数据源也设好了

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: