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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

asp form static fields

Status
Not open for further replies.

edgarv

MIS
Jul 25, 2003
248
US
Hello, I am working on a form that has 7 columns. 3 of those colums have static text and 4 have text that needs to be entered. how could I save all the data to ms access?

I am not sure if this is the right forum to ask this question. If is not I apologize.
 
You need to submit the contents of the form to a page that will update the database. Lets call the first page editrecordform.asp it is going to have a form on with one text box that you can update text in. Yours is more complicated but the principle is the same.

<form method="post" action="editrecord.asp">
<input type="text" name="MyName">
<input type="submit" value="Update Database">
</form>

Now you make a separate page calle editrecord.asp with the following code. This example uses a database called mydatabase.mdb and contains a table called Users and this table has a column called MyName.

Once it establishes a connection to the database it assigns the value which we got from the form above

<input type="text" name="MyName">

and puts it into the recordset. This recordset is then written to the database.

That is the most basic example I can think of but obviously as the datbase grows in size with extra columns and data types you can start to do some more interesting things.

<HTML>
<BODY>
<FONT FACE="Verdana" SIZE="2">
<%
'Dimension variables
Dim adoCon 'Holds the Database Connection Object
Dim rsAddRecord 'Holds the recordset for the new record to be added
Dim strSQL 'Holds the SQL query to query the database
Dim compare

'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("mydatabase.mdb")

'Create an ADO recordset object
Set rsAddRecord = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT Users.* FROM Users"

'Set the cursor type we are using so we can navigate through the recordset
rsAddRecord.CursorType = 2

'Set the lock type so that the record is locked by ADO when it is updated
rsAddRecord.LockType = 3

'Open the recordset with the SQL query
rsAddRecord.Open strSQL, adoCon

rsAddRecord.AddNew

'Add a new record to the recordset

rsAddRecord.Fields("MyName") = Request.Form("MyName")

'Write the updated recordset to the database
rsAddRecord.Update

'Reset server objects
rsAddRecord.Close
Set rsAddRecord = Nothing
Set adoCon = Nothing



%>
</BODY>
</HTML>
 
Thank you emozley,
got it. that was going to be my next question. I appreciate the help. I now just have to figure out how am I going to build my table for this form.

thaks again
 
Golden rules for designing a datbase.

Make sure you have a UniqueID (autonumber) for each record.
Make sure relevant information is stored together in suitable tables.
Normalize the database - do not have duplicate information.

There are probably many more golden rules but those 3 are a good place to start.
 
I'll give it a try.

Is there a way to pass the aoutonuber id form one table to another in asp?
 
Not that I know of - the way I tend to design things is that I have my master table with core information including an autonumber. I then design the ASP front end so that when you add a new record it updates the master table, then finds out what the autonumber was then updates the other tables with that number. Having autonumber in all the tables would be suicidal as the chances of them staying in sync would be next to nil.
 
ahh I see once again I appreciate the help

thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top