How to insert into table in VB
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(' 开发者_如何学Python" & a & " ',' " & b & " ' ) ", cn, adOpenKeyset, adLockOptimistic
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.
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.
精彩评论