Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Any sample ASP script for adding new records into database?

Status
Not open for further replies.

Beng79

Technical User
Jan 5, 2006
48
HK
Good day to all,

My asp script requires users to enter data in textboxes and capture them into the database as new records.

Does anyone know of any sample ASP scripts or tutorials?

Thanks
 
here is the sample script in the simplests form...

Code:
<%
Dim conn, sql

conn="your connection string to access db"
conn.open()
sql = "insert into mytable(field1,field2)"&_
      " values ('"&request.form("textbox1")&"',"&_
      " '"&request.form("textbox2")&"') "
conn.execute(sql)
conn.close()
set conn=Nothing
%>

post back if you have any questions...

-DNG
 
For the sample script, how do I ensure that the data from textbox1 goes to field1 in the database table and textbox2 goes to field2 subsequently?

If I have multiple text boxes which means more than one row of data to be captured, how do I do that?



 
to answer your first question...its pretty straight forward...the fields we specify in the insert statement and the values that need to be insert should be in the same order...i mean...when we say

insert into mytable (field1, field2) VALUES (field1val, field2val)

field1val and field2val are the values for field1 and field2 respectively...

and for the second question....you need to execute this same sql statement for multiple time with different values...

post back if you have more questions..

-DNG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top