Print Page | Close Window

ADO > Insert Into Statement Problems...

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=6998
Printed Date: 29 March 2026 at 4:41am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: ADO > Insert Into Statement Problems...
Posted By: Krisc
Subject: ADO > Insert Into Statement Problems...
Date 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...




Replies:
Posted By: Mart
Date Posted: 04 November 2003 at 1:58pm
Is this code in asp.net or asp?


Posted By: Krisc
Date 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...



-------------
DigitalExplosions - http://www.DigitalExplosions.com (My Website)


Posted By: MorningZ
Date 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

http://www.4guysfromrolla.com/webtech/chapters/ASPNET/ch06.2.shtml - exellent article on 4guys showing the basics of ADO.NET



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Bunce
Date 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.


Posted By: Diep-Vriezer
Date 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..


Posted By: MorningZ
Date Posted: 06 November 2003 at 8:53am

For the record, "Password" is http://www.flws.com.au/showusyourcode/codeLib/code/odbc_keywords.asp - 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


Posted By: Mart
Date 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




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net