Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - ADO > Insert Into Statement Problems...
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

ADO > Insert Into Statement Problems...

 Post Reply Post Reply
Author
Krisc View Drop Down
Newbie
Newbie
Avatar

Joined: 25 January 2003
Location: United States
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote Krisc Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 04 November 2003 at 1:58pm
Is this code in asp.net or asp?
Back to Top
Krisc View Drop Down
Newbie
Newbie
Avatar

Joined: 25 January 2003
Location: United States
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote Krisc Quote  Post ReplyReply Direct Link To This Post 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...

Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Bunce View Drop Down
Senior Member
Senior Member
Avatar

Joined: 10 April 2002
Location: Australia
Status: Offline
Points: 846
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bunce Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
Diep-Vriezer View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 August 2003
Location: Netherlands
Status: Offline
Points: 831
Post Options Post Options   Thanks (0) Thanks(0)   Quote Diep-Vriezer Quote  Post ReplyReply Direct Link To This Post 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..
Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.