problems inserting into database.

Results 1 to 2 of 2

Thread: problems inserting into database.

  1. #1
    Join Date
    Dec 1969

    Default problems inserting into database.

    Hi: I am not able to insert records using SQL statements. It says error in insert syntax. thanks for helping out.ciao. jay.<% ' Declaring variables Dim name, email, country, comments, data_source, con, SQL ' A Function to check if some field entered by user is empty Function ChkString(string) If string = "" Then string = " " ChkString = Replace(string, "'", "''") End Function ' Receiving values from Form name = ChkString(Request.Form("un")) pass = ChkString(Request.Form("pw")) data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _ Server.MapPath("testing.mdb") SQL="insert into mytable(user, password) values('"+name+"','"+pass+"')" 'Response.Write "SQL is " & SQL & "" & vbNewLine 'insert into employee'(first, last, age, address, city, state)'values ('Luke', 'Duke', 45, '2130 Boars Nest', 'Hazard Co', 'Georgia');'sql_insert = "insert into mytable (user, password) values ('" & _ ' name & "', & pass & "')" ' Creating Connection Object and opening the database Set con = Server.CreateObject("ADODB.Connection") con.Open data_source con.Execute SQL ' Done. Close the connection con.Close Set con = Nothing %>
    Mercedes-benz history
    Last edited by Jay; 04-16-2011 at 01:26 AM.

  2. #2
    Join Date
    Dec 1969

    Default So what did the DEBUG say?

    I see you *had* a Response.Write of the SQL string in there. Why&#039;d you take it out? What did *it* report that the SQL you were/are using was/is?<BR><BR>Oh! Is this Access??? In Access, "password" (and maybe "user) is a KEYWORD and so cannot be used as a field name in SQL...unless you surround it by [...] to tell Access to ignore the fact it is a keyword.<BR><BR>So try:<BR><BR>SQL="insert into mytable([user], [password]) values(&#039;" & name & "&#039;,&#039;" & pass & "&#039;)"<BR><BR>Doh. Yeah, I looked at your code again. An ".mdb" file, so definitely you need the [...] around "password". <BR><BR>Also, *please* use & for string concatenation in VBS. Trust me, it will keep you out of trouble some time in the future. Using + does *NOT* ensure concatenation...if VBS can interpret + as addition, even if it needs to convert a string to a number, it will do so...just when you don&#039;t want it to.<BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts