| Author |
Topic Search Topic Options
|
Krisc
Newbie
Joined: 25 January 2003
Location: United States
Status: Offline
Points: 7
|
Post Options
Thanks(0)
Quote Reply
Topic: ADO > Insert Into Statement Problems... Posted: 04 November 2003 at 1:52pm |
Hi, I am working with ASP.NET...but the code is from my ASP days...and I can read etc from my database, but I can't seem to get the adding to work! I was wondering if someone could help me out...
Here is the code...
Sub CreateUser( Src As Object, E as EventArgs ) Dim tPass1, tPass2, tUser tPass1 = Password1.Text tPass2 = Password2.Text tUser = Username.Text Message.Text = "" If tPass1 = tPass2 Then Dim dbconn, rs, x, y, conn, connConfig, bUserFound, xv bUserFound = False
conn = Server.CreateObject("ADODB.Connection") conn.Provider = "Microsoft.Ject.OLEDB.4.0" connConfig = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("databases/users.mdb") conn.Open( connConfig ) rs = Server.CreateObject("ADODB.Recordset") rs.Open("users", conn) do until rs.EOF for each x in rs.fields if x.name = "Username" then Dim tLoweredUser as String Dim tLoweredValue as String tLoweredUser = tUser.ToLower() tLoweredValue = x.value tLoweredValue = tLoweredValue.ToLower() if tLoweredValue = tLoweredUser then bUserFound = True end if end if next rs.movenext loop conn.Close if bUserFound then Message.Text = "Username already exists in database!" Exit Sub else 'conn = Nothing conn = Server.CreateObject("ADODB.Connection") conn.Provider = "Microsoft.Jet.OLEDB.4.0" conn.Open(server.mapPath("databases/users. mdb")) Dim sql sql = "INSERT INTO users (Username,Password,Rank,Joined,Profile,Website)" sql = sql & " VALUES " sql = sql & "('" & tUser & "'," sql = sql & "'" & tPass1 & "'," sql = sql & "'1','" & now() & "','a','a')" On Error Resume Next conn.Execute( sql ) if err.Number <> 0 then Message.Text = "Cannot register, please contact the administrator!" Response.Write(err.Number & " :: " & err.description) Response.Write("<br />") Response.Write(sql) else Message.Text = "You have been registered!" end if conn.close end if Else Message.Text = "Passwords do not match!" Exit Sub End If End Sub
|
It says:
-2147217900 :: Syntax error in INSERT INTO statement. INSERT INTO users (Username,Password,Rank,Joined,Profile,Website) VALUES ('admin','1234','1','11/4/2003 3:38:47 PM','a','a')
The first line is the err.number and err.description
the second line is sql's value...
Thanks... It has been frustrating me ever since last night...I spent at least a good 2 hours trying to figure out what was wrong without finding a thing... 
Edited by Krisc
|
 |
Mart
Senior Member
Joined: 30 November 2002
Status: Offline
Points: 2304
|
Post Options
Thanks(0)
Quote Reply
Posted: 04 November 2003 at 1:58pm |
|
Is this code in asp.net or asp?
|
 |
Krisc
Newbie
Joined: 25 January 2003
Location: United States
Status: Offline
Points: 7
|
Post Options
Thanks(0)
Quote Reply
Posted: 04 November 2003 at 2:07pm |
Some of it is in ASP.NET but the actual database stuff is all in ASP. The ASP.NET code includes the Sub statements, the textbox statements etc. Message is an <asp:Label> and Username and Password are both <asp:TextBox>s...
|
 |
MorningZ
Senior Member
Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
|
Post Options
Thanks(0)
Quote Reply
Posted: 04 November 2003 at 6:38pm |
ASP 3.0 != ASP.NET
do your code in ASP.NET terms and believe it or not, it'll work
exellent article on 4guys showing the basics of ADO.NET
|
|
Contribute to the working anarchy we fondly call the Internet
|
 |
Bunce
Senior Member
Joined: 10 April 2002
Location: Australia
Status: Offline
Points: 846
|
Post Options
Thanks(0)
Quote Reply
Posted: 06 November 2003 at 3:44am |
Dates need to be surrounded by ## in Access. Password may also be a reserved word.
But yes, there's not much point coding in .net if you're not going to make the most of its features.
For starters, forget about 'On Error Resume Next!' We've now got structured error handling. Try/Catch/Finally is the way to go.
Cheers, Andrew
|
|
There have been many, many posts made throughout the world...
This was one of them.
|
 |
Diep-Vriezer
Senior Member
Joined: 06 August 2003
Location: Netherlands
Status: Offline
Points: 831
|
Post Options
Thanks(0)
Quote Reply
Posted: 06 November 2003 at 7:43am |
|
This looks a lot like ASP3 to me, wich wouldn't work with .NET. I had the same problem. Look about 2 months ago for a topic named 'Databases'.
|
|
Gone..
|
 |
MorningZ
Senior Member
Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
|
Post Options
Thanks(0)
Quote Reply
Posted: 06 November 2003 at 8:53am |
For the record, "Password" is not a reserved word
for two replies on this thread, read first line in his post: Hi, I am working with ASP.NET...but the code is from my ASP days.
oops, you missed that... lol
|
|
Contribute to the working anarchy we fondly call the Internet
|
 |
Mart
Senior Member
Joined: 30 November 2002
Status: Offline
Points: 2304
|
Post Options
Thanks(0)
Quote Reply
Posted: 06 November 2003 at 10:52am |
I was getting mixed messages, he/she said it was asp but it had these arguments:
Sub CreateUser( Src As Object, E as EventArgs )
which are asp.net and it refers to a label or literal control:
Message.Text = "Passwords do not match!"
So i was a bit confused
|
 |