Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: check if record exists, before inserting it


Message #1 by jay48202@y... on Fri, 4 Oct 2002 21:12:48
Hi,

I am inserting records into database with the following statement.

sql_insert = "insert into tbLbls(PartType,NumLabels, Label) values ('" & 
vPartType & "','" & vNumLabels & "','" & arraylbl & "')"
	 Conn.Execute=sql_insert

It is working fine. In the tbLbs(Table) PartType is the PrimaryKey. 

Here is my question,

How do I check, if a record exists with that PartType before using the 
above statement. I wanted to check if a record already exists before 
inserting one. If exists, I wanna inform in the browser saying record 
already exists else, insert the record. 

Thanks,
Jay



Message #2 by "Peter Foti (PeterF)" <PeterF@S...> on Fri, 4 Oct 2002 16:27:42 -0400
Just run a query that looks for that PartType and see if anything was
returned.

SQLStr = "SELECT PartType FROM tbLbls WHERE PartType='" & vPartType & "'"
oRS = Conn.Execute(SQLStr)
If Not oRS.EOF Then
   ' A part with this PartType exists, tell the user
Else
   ' Perform the insert
End If


> -----Original Message-----
> From: jay48202@y... [mailto:jay48202@y...]
> Sent: Friday, October 04, 2002 9:13 PM
> To: ASP Databases
> Subject: [asp_databases] check if record exists, before inserting it
> 
> 
> Hi,
> 
> I am inserting records into database with the following statement.
> 
> sql_insert = "insert into tbLbls(PartType,NumLabels, Label) 
> values ('" & 
> vPartType & "','" & vNumLabels & "','" & arraylbl & "')"
> 	 Conn.Execute=sql_insert
> 
> It is working fine. In the tbLbs(Table) PartType is the PrimaryKey. 
> 
> Here is my question,
> 
> How do I check, if a record exists with that PartType before 
> using the 
> above statement. I wanted to check if a record already exists before 
> inserting one. If exists, I wanna inform in the browser saying record 
> already exists else, insert the record. 
> 
> Thanks,
> Jay
> 
> 
> 
> 

  Return to Index