|
-
May 30th, 2006, 12:34 PM
#1
Thread Starter
Frenzied Member
check success of sql insert query
VB Code:
If (cn.State = adStateOpen) Then
Dim Str As String
Str = "INSERT INTO " & SQLTable & "(Username, Password) VALUES(" & Text1.Text & "," & Text2.Text & ")"
adoRS.Open str, cn
End If
how can i tell if the insert was successful?
and does the inset syntax look correct to you guys? i havent tested it yet
edit**********
tested it and it throws an 'sql sntax' error
-
May 30th, 2006, 12:36 PM
#2
Re: check success of sql insert query
Str = "INSERT INTO " & SQLTable & "(Username, Password) VALUES('" & Text1.Text & "','" & Text2.Text & "')"
those are strings....
so it needed the ' '
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
May 30th, 2006, 12:39 PM
#3
Re: check success of sql insert query
Well, first off, you need to encapsulate string entries in single quotes
VB Code:
VALUES('" & Text1.Text & "','" & Text2.Text & "')"
Also, you OPEN a recordset that is created using a SELECT. For action queries, you use the Execute method of the connection object.
-
May 30th, 2006, 12:54 PM
#4
Thread Starter
Frenzied Member
Re: check success of sql insert query
thanks, its still throwing the error
-
May 30th, 2006, 12:58 PM
#5
Re: check success of sql insert query
 Originally Posted by Pouncer
thanks, its still throwing the error 
1. Post what you currently have.
2. What error is it throwing?
-
May 30th, 2006, 12:58 PM
#6
Re: check success of sql insert query
 Originally Posted by Hack
Well, first off, you need to encapsulate string entries in single quotes
VB Code:
VALUES('" & Text1.Text & "','" & Text2.Text & "')"
Also, you OPEN a recordset that is created using a SELECT. For action queries, you use the Execute method of the connection object.
oh yeah... execute lol
Pouncer.. whats the error and what line is it stopping at?
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
May 30th, 2006, 01:20 PM
#7
Re: check success of sql insert query
Password is a keyword. Place square brackets around field names that are also keywords.
& "(Username, [Password]) VALUES(" &
Also, add a space between the table name and the list of columns
Str = "INSERT INTO " & SQLTable & " (Username
[Edit]
Sorry, I just ran a quick test. The space is not required...
Last edited by brucevde; May 30th, 2006 at 01:23 PM.
-
May 30th, 2006, 01:27 PM
#8
Re: check success of sql insert query
 Originally Posted by brucevde
Password is a keyword. Place square brackets around field names that are also keywords.
I completely forgot about that. I always think in terms of PWD = whatever.....but, he is right....the word Password is a keyword. 
 Originally Posted by brucevde
Sorry, I just ran a quick test. The space is not required...
I have run into problems with VALUES clauses and spaces, or more accurately, the lack of a space, so I think it is always a good idea to put a space between the table name and the list of columns.
-
May 30th, 2006, 01:32 PM
#9
Thread Starter
Frenzied Member
Re: check success of sql insert query
ok thansk guys i got it to work..
VB Code:
Str = "INSERT INTO testuser (Username, Password) VALUES('" & Text1.Text & "','" & Text2.Text & "')"
cn.Execute Str
but how can i make it msgbox or something after the execute was successful
-
May 30th, 2006, 01:33 PM
#10
Re: check success of sql insert query
VB Code:
Str = "SELECT COUNT("username") FROM " & SQLTable & " WHERE username = '" & Text1.Text & "',"
adoRS.Open str, cn
Msgbox adoRS.Fields.Item("username").Value
If the message box is blank, your INSERT failed.
-
May 30th, 2006, 02:51 PM
#11
Thread Starter
Frenzied Member
Re: check success of sql insert query
nice one Hack.
-
May 30th, 2006, 05:41 PM
#12
Re: check success of sql insert query
Another option
VB Code:
Dim lngRowsAffected As Long
Str = "INSERT INTO testuser (Username, Password) VALUES('" & Text1.Text & "','" & Text2.Text & "')"
cn.Execute Str, lngRowsAffected
If lngRowsAffected > 0 Then
msgbox "Insert Successful"
End if
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|