首页 > 开发 > 综合 > 正文

vb与sqlserver数据库连接的问题

2024-07-21 02:20:33
字体:
来源:转载
供稿:网友
 

最近编一个物资管理系统,用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 添加了,数据源也设好了

菜鸟学堂:
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表