VB中如何向表中插入数据

发布于 2024-10-27 11:26:36 字数 292 浏览 0 评论 0原文

我想在VB中插入一些字段到表中。但它没有给出任何结果。

Dim a As String
a = s_up.Text1.Text
Dim b As String
b = s_up.Text2.Text
Set rs = Nothing
rs.Open "insert into profile (user_name,first_name) values(' " & a & " ',' " & b & " ' ) ", cn, adOpenKeyset, adLockOptimistic

I want to insert into table some fields in VB. But it is not giving any result.

Dim a As String
a = s_up.Text1.Text
Dim b As String
b = s_up.Text2.Text
Set rs = Nothing
rs.Open "insert into profile (user_name,first_name) values(' " & a & " ',' " & b & " ' ) ", cn, adOpenKeyset, adLockOptimistic

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

肤浅与狂妄 2024-11-03 11:26:37

您的 SQL 代码不返回结果集,因此结果应该是实例化的记录集,但使用 State = adStateClosed,因此您将无法用它做太多事情,例如没有行也没有字段,可以不测试 RecordCOunt 或 EOF 等。

Your SQL code does not return a resultset, so the result should be an instantiated recordset but with State = adStateClosed, so you won't be able to do much with it e.g. has no rows nor fields, can't be tested for RecordCOunt nor EOF, etc.

讽刺将军 2024-11-03 11:26:36

假设您之前已经设置了 ADO 对象,那么在打开结果集之前将其设置为 Nothing 可能不是一个好主意。尝试删除此行看看是否有帮助。哦

Dim a As String
a = s_up.Text1.Text
Dim b As String
b = s_up.Text2.Text
rs.Open "insert into profile (user_name,first_name) values(' " & a & " ',' " & b & " ' ) ", cn, adOpenKeyset, adLockOptimistic

,是的,这种方法并不是最安全的。阅读避免 SQL 注入的最佳实践。

Assuming you've set up the ADO object earlier, setting it to Nothing before opening the result set probably isn't a good idea. Try removing this line to see if it helps. ie

Dim a As String
a = s_up.Text1.Text
Dim b As String
b = s_up.Text2.Text
rs.Open "insert into profile (user_name,first_name) values(' " & a & " ',' " & b & " ' ) ", cn, adOpenKeyset, adLockOptimistic

oh yeh, and this approach isn't the most secure. Have a read up on best practices to avoid SQL injection.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文