Insert Into (query)

Results 1 to 2 of 2

Thread: Insert Into (query)

  1. #1
    Join Date
    Dec 1969

    Default Insert Into (query)

    Hi All,<BR><BR>I&#039;m simply adding some fields into the database but i don&#039;t know what is the problem with the query below it&#039;s not giving any error but showing Duplicate Project_id which is in else statement but there is no data in database.<BR><BR>&#060;% <BR>fname=request.form("a1")<BR>lname=request.form ("a2")<BR>profile = request.form("a3")<BR>mname=request.form("a4")<BR> business=Request.form("a5")<BR>%&#062;<BR>&#060;!--#include file ="connect.txt"--&#062;<BR>&#060;% <BR>SET RS = Server.CreateObject("ADODB.Recordset")<BR>RS.Open "SELECT * FROM Add_Master" ,Con<BR>if RS.EOF then<BR> sql = "INSERT INTO Add_Master(F_Name, L_Name, Profile, M_Name, Business)"<BR> sql = sql & " VALUES (&#039;" & fname & "&#039;, &#039;" & lname & "&#039;, &#039;" & profile & "&#039;, &#039;" & mname & "&#039;, &#039;" & business & "&#039;)"<BR> response.write(sql)<BR> Con.Execute sql<BR> response.write("Record Inserted")<BR>else<BR> response.write("Duplicate Project_id")<BR>end if<BR>RS.Close<BR>Con.Close<BR>%&#062;

  2. #2
    Join Date
    Dec 1969

    Default RE: Insert Into (query)

    I think there&#039;s an logic problem here. <BR><BR>*IF* RS.EOF <BR> &#039;do the update<BR>ELSE<BR> &#039;response.write duplicate ID<BR><BR>So when you alway get the Duplicate Project_ID, (and not the insert) RS.EOF is not true. <BR>This seems logic since you select *all* rows from the table in you RS.Open statement, so when there are 1 or more rows in the Add_Master table RS.Eof is never true! This means that after the very first insert you won&#039;t be able to insert any rows.<BR><BR>My guess is you want to check if the Project_ID already exists in the table, your select statement in the RS.Open line should look something like this:<BR><BR>SELECT * FROM Add_Master WHERE ProjectID = [projectID]<BR><BR>There&#039;s an Faq on on this subject:<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