VB中如何向表中插入数据
我想在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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的 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.假设您之前已经设置了 ADO 对象,那么在打开结果集之前将其设置为
Nothing
可能不是一个好主意。尝试删除此行看看是否有帮助。哦,是的,这种方法并不是最安全的。阅读避免 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. ieoh yeh, and this approach isn't the most secure. Have a read up on best practices to avoid SQL injection.