Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Searching a Database (the easy way?)
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Searching a Database (the easy way?)

 Post Reply Post Reply
Author
fark View Drop Down
Newbie
Newbie


Joined: 04 November 2003
Location: United States
Status: Offline
Points: 29
Post Options Post Options   Thanks (0) Thanks(0)   Quote fark Quote  Post ReplyReply Direct Link To This Post Topic: Searching a Database (the easy way?)
    Posted: 06 November 2003 at 4:13pm

Thanks to everyones incredible help I have used sql insert to create a database conversion program that actually works (fast!!) and is incredibly small as you can see.  My question is I have a program that adds the records efficiently now how do I efficiently check to see if the record is already there so I don't make a duplicate.  The field TrackingNumber should be unique in every case. 

What would this do?

strsql = "SELECT * FROM UPS WHERE TrackingNumber = """ & BARCODE & """;"

Conn.execute(strsql)

Does this statement return anything to let me know what the result of the execute was (let me know if it found a match)?

Is there another easy way to search?  Thanks Again!!!!!

<!-- #include file="aspfunc.inc" -->
<%

Dim xDb_Conn_Str
Dim Conn
Dim strsql
Dim ConFields
Dim dcSpeedee, rsSpeedee
Const DSN_NAME = "DSN=Speedee Track"
Dim I
Dim Fields, Values
Dim Counter


xDb_Conn_Str1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("sd\shippingdatabase.mdb") & ";"
set conn = Server.CreateObject("ADODB.Connection")
conn.Open xDb_Conn_Str1

Set dcSpeedee = Server.CreateObject("ADODB.Connection")
dcSpeedee.ConnectionTimeout = 20
dcSpeedee.CommandTimeout = 50
dcSpeedee.Open DSN_NAME
Set rsSpeedee = Server.CreateObject("ADODB.Recordset")
rsSpeedee.Open "SELECT * FROM Archive ;", dcSpeedee, adOpenStatic, adLockReadOnly

ConFields=LoadFile("convertspeedee.con")

Counter=0
Do While Not rsSpeedee.EOF
Fields=""
Values=""
strsql=""
strsql = "INSERT INTO UPS (ParcelCarrier "

I=0
Do While I<UBound(ConFields)
 If rsSpeedee(ConFields(I))<>"" Then
  If Asc(rsSpeedee(ConFields(I)))<>0 Then
   'Response.Write rsSpeedee(ConFields(I)).Type
   Fields = Fields & ", " & ConFields(I+1)
   Values = Values & ", '" & Replace (CStr(rsSpeedee(ConFields(I))),"'","") & "'"
   'Response.Write "<BR>" & ConFields(I+1) & "<BR>" & rsSpeedee(ConFields(I)) & "<BR>"
  End If
 End If
 I=I+2
Loop

strsql = strsql & Fields & ") Values ('Speedee' " & Values & " );"

Conn.execute(strsql)
Counter=Counter+1
Response.Write Counter & " Total Records Added"
rsSpeedee.MoveNext
Loop

Response.Write "END"
%>

Back to Top
pmormr View Drop Down
Senior Member
Senior Member


Joined: 06 January 2003
Location: United States
Status: Offline
Points: 1479
Post Options Post Options   Thanks (0) Thanks(0)   Quote pmormr Quote  Post ReplyReply Direct Link To This Post Posted: 10 November 2003 at 4:12pm

<!-- #include file="aspfunc.inc" -->
<%

Dim xDb_Conn_Str
Dim Conn
Dim strsql
Dim ConFields
Dim dcSpeedee, rsSpeedee
Const DSN_NAME = "DSN=Speedee Track"
Dim I
Dim Fields, Values
Dim Counter


xDb_Conn_Str1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("sd\shippingdatabase.mdb") & ";"
set conn = Server.CreateObject("ADODB.Connection")
conn.Open xDb_Conn_Str1

Set dcSpeedee = Server.CreateObject("ADODB.Connection")
dcSpeedee.ConnectionTimeout = 20
dcSpeedee.CommandTimeout = 50
dcSpeedee.Open DSN_NAME
Set rsSpeedee = Server.CreateObject("ADODB.Recordset")
rsSpeedee.Open "SELECT * FROM Archive ;", dcSpeedee, adOpenStatic, adLockReadOnly

Dim checkdoubles
Set checkdoubles = Server.CreateObject("ADODB.Recordset")
checkdoubles.open "SELECT * FROM UPS WHERE TrackingNumber = """ & BARCODE & """;", dcSpeedee

If checkdoubles.bof and checkdoubles.eof then
ConFields=LoadFile("convertspeedee.con")

Counter=0
Do While Not rsSpeedee.EOF
Fields=""
Values=""
strsql=""
strsql = "INSERT INTO UPS (ParcelCarrier "

I=0
Do While I<UBound(ConFields)
 If rsSpeedee(ConFields(I))<>"" Then
  If Asc(rsSpeedee(ConFields(I)))<>0 Then
   'Response.Write rsSpeedee(ConFields(I)).Type
   Fields = Fields & ", " & ConFields(I+1)
   Values = Values & ", '" & Replace (CStr(rsSpeedee(ConFields(I))),"'","") & "'"
   'Response.Write "<BR>" & ConFields(I+1) & "<BR>" & rsSpeedee(ConFields(I)) & "<BR>"
  End If
 End If
 I=I+2
Loop

strsql = strsql & Fields & ") Values ('Speedee' " & Values & " );"

Conn.execute(strsql)
Counter=Counter+1
Response.Write Counter & " Total Records Added"
rsSpeedee.MoveNext
Loop

Else
Response.Write "RECORD ALREADY ADDED"
End If

Response.Write "END"
%>

you may need to move some stuff around to get it to work properly, but you should get the main idea...



Edited by pmormr
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.