weixin_43539387
weixin_43539387
2020-01-30 17:47

VB中链接数据库插入数据问题?

  • sql
  • 开发语言

这是窗体里的代码:executesql "insert into 收入(日期,方式,金额,项目,序号) values(" & Format(DTPicker1.Value, "yyyy-mm-dd") & "," & Combo2.Text & "," & Text2.Text & "," & Combo1.Text & "," & Text3.Text & "," & List1.Text & "," & b & ") ", str_text
这是模块中引用的代码:Public Function executesql(ByVal sql As String, msgstring As String)
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim stokens() As String
On Error GoTo executesql_onerror
Set cnn = New ADODB.Connection
cnn.Open connectstring
stokens = Split(sql)
If InStr("insert,delete,update", UCase$(stokens(0))) Then
cnn.Execute sql
msgstring = stokens(0) & "查询成功"
Else
Set rst = New ADODB.Recordset
rst.Open Trim$(sql), cnn, adOpenKeyset, adLockOptimistic
Set executesql = rst
msgstring = "查询到" & rst.RecordCount & "条记录"
executesql_exit:
Set cnn = Nothing
Set rst = Nothing
Exit Function
executesql_onerror:
msgstring = "查询错误" & Err.Description
Resume executesql_exit
End If
End Function
执行之后数据显示成功但是数据库查不到输入的数据

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐