ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #16  
Old August 25th, 2003, 12:06 PM
Vlince Vlince is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Canada, Quebec, Montreal
Posts: 410 Vlince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
That's why it's ALWAYS good practice to Response.Write your SQL Queries *******B E F O R E********** you execute them...


For example, get into the habit of doing this:


<%
. . .
. .
.
SQL_DetailsRetreival = "SELECT IPaddress FROM tblIP WHERE IPaddress ='" & grabIP & "'"

SQL_InsertData = "insert into tblIP (IPaddess) values (" & grabIP & ")"


'FOR DEBUG ONLY
Response.Write SQL_DetailsRetreival & "<hr>"
Response.End



SET objRst = objConnect.execute(SQL_DetailsRetreival)
. . .
. .
.
%>
Then COPY/PASTE the query result from your browser into your database, run it see if it works!
Then comment the two lines under the 'FOR DEBUG ONLY section


Now your INSERT query should look like this:

SQL_InsertData = "insert into tblIP (IPaddess) values ('" & grabIP & "')"

Hope this helps!
Sincerely

Vlince

Reply With Quote
  #17  
Old August 25th, 2003, 01:49 PM
seb835 seb835 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: UK, London
Posts: 95 seb835 User rank is Lance Corporal (50 - 100 Reputation Level)seb835 User rank is Lance Corporal (50 - 100 Reputation Level)seb835 User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 9 h 36 m 11 sec
Reputation Power: 6
Thanks Vlince, the code works perfectly and I can now see how the syntax works.

However on the subject of syntax, how would you go about inserting more than one peice of data in to more than one table column?

For example I have 3 strings:

sessionID, URLName, URLAddress

How could I insert these 3 pieces of data in the same table in different columns so that one row contains these 3 peices of information?

here is the SQL that obviously only inserts one peice of info:

SQL_InsertData = "insert into tblURL (urlName) values ('" & URLName & "')"


many thanks.

Reply With Quote
  #18  
Old August 25th, 2003, 01:56 PM
Vlince Vlince is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Canada, Quebec, Montreal
Posts: 410 Vlince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Look at the documentation of an INSERT query
Here...

INSERT [INTO] table_or_view [(column_list)] data_values


Example
INSERT INTO MyTable (PriKey, Description)
VALUES (123, 'A description of part 123.')


Hope this helps!
Sincerely

Vlince

Reply With Quote
  #19  
Old August 25th, 2003, 01:59 PM
karsh44's Avatar
karsh44 karsh44 is offline
Just another guy
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jun 2003
Location: Wisconsin
Posts: 2,915 karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 13 h 13 m 21 sec
Reputation Power: 76
Separate the column and value names with commas.
Code:
 SQL_InsertData = "INSERT INTO tblURL (column1, column2, column3) values (value1, value2, value3) 

Check out www.w3schools.com/sql for some easy lessons on basic sql syntax.

edit: darn, too slow.
__________________
--Dave--

U2kgSG9jIExlZ2VyZSBTY2lzLCBOaW1pdW0gRXJ1ZGl0aW9uaXMgSGFiZXM=

Reply With Quote
  #20  
Old August 25th, 2003, 02:02 PM
Vlince Vlince is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Canada, Quebec, Montreal
Posts: 410 Vlince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
LOL

Well your example shows an INSERT query with 3 fields which is what the poster wanted, I only gave him 2 fields...making him work a little ;-)

Reply With Quote
  #21  
Old August 25th, 2003, 02:34 PM
seb835 seb835 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: UK, London
Posts: 95 seb835 User rank is Lance Corporal (50 - 100 Reputation Level)seb835 User rank is Lance Corporal (50 - 100 Reputation Level)seb835 User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 9 h 36 m 11 sec
Reputation Power: 6
Hahaha, yeah ive sure been working hard tonight!!!!!!!!!!

Well thanks to you guys I have a MUCH better understanding of using databases with ASP and ive finished! It all works! So thanks a million and see you soon!

Reply With Quote
  #22  
Old August 25th, 2003, 02:38 PM
Vlince Vlince is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Canada, Quebec, Montreal
Posts: 410 Vlince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Where's our money?

Did you really think that our advice was free ???

Are you serious?

Anyway, a little donation to karsh44 & Vlince inc. foundation would be appreciated AND EXPECTED. period.



Hope this helps!
Sincerely

Vlince

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > How to use SQL to add a record?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT