PDA

View Full Version : Help with simple ASP + SQL?


Iconoclast
03-30-2009, 06:15 AM
Hi guys, I'm playing around with ASP a bit more and now I'm trying to figure out some basic SQL connections and such. I've made a very simple database in Access, which only has one table. It has the following 3 columns:

NumericTest (int)
DateTest (datetime)
StringTest (text)

For each column, I have 3 records of example data.

Although this database is extremely simple, I have a fairly good knowledge of many advanced Access concepts; I'm just using this very simple example to try to learn to use it with ASP.

Anyways, I'm just trying to do some really basic stuff. What I want to do it to display the database records in an HTML table (I know I have to use Response.Write to do this, but how do I create the connection to the database? Do I do it using CreateObject? Can someone provide me with an example or tell me how it's done?)

Next, I'd like to be able to include a simple search filter on the page...for example, if a user wanted to find a record containing the string "boo" they could type it into a textbox, and have the table only display records that contain that string.

Lastly, I'd like to be able to have the user to select a sort option...in other words, allowing them to sort via ascending or descending on one column.

Can anyone help me out with this? I would greatly appreciate it! Thanks! :D

Spudhead
03-30-2009, 06:29 PM
There's a basic introduction, with copyable code, to connecting with an Access database here:
http://www.codeproject.com/KB/database/accessdb.aspx

Once you've got something up and running, chuck it up here and we'll see if we can get some filtering working on it.

Old Pedant
03-30-2009, 11:02 PM
And look here:
http://www.ClearviewDesign.com/Newbie

In the demos, I show sorting columns both all in ASP and in JS code in the browser, your choice.

You can view the source code to see one way of connecting to the Access DB. That's ancient history code (2001, I think), and I've since moved to using the JET OLEDB driver. You can see that kind of connection in my "Calendar of Events" demo.

Yeah, look here:
http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=140

Written about the same time as the demo.

Bullschmidt
03-30-2009, 11:05 PM
And here:

ASP Tutorial
http://www.w3schools.com/asp

Iconoclast
04-01-2009, 02:57 AM
Okay, I have the connection working, but I'm having some troubles implementing the filter. Here's what I've got so far:

(also, I changed my database to make more sense, rather than just be a test...it now contains columns for:
Student First Name
Student Last Name
Student Number
Student Date of Birth)

page1.asp (main page):

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>asp test</title>

</head>

<body>


<form name="filter" action="page2.asp" method="post">

<strong>Filter Results by Last Name: </strong>
<input type="text" name="flname" />
<input type="submit" value="Go!" />

</form>



<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("testdb.mdb"))

set rs = Server.CreateObject("ADODB.recordset")
dim filterString
rs.Open "SELECT * FROM student", conn
%>


<table border="1" width="50%">
<%
do until rs.EOF
Response.write("<tr><td>" & rs.fields(1) & "</td><td>" & rs.Fields(2) & "</td><td>" & rs.Fields(3) & "</td><td>" & rs.Fields(4) & "</td></tr>")
rs.MoveNext
loop
rs.close
conn.close
%>
</table>


</body>
</html>


Here's my page2.asp (basically the same, but I tried to implement the filter using Request.Form getting the value from page1 and using it in the SQL SELECT statement with LIKE:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>asp test with sql</title>

</head>

<body>




<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("testdb.mdb"))

set rs = Server.CreateObject("ADODB.recordset")
dim filterString = Request.Form("flname")
rs.Open "SELECT * FROM student WHERE lname LIKE '" & filterString & "%'", conn
%>


<table border="1" width="50%">
<%
do until rs.EOF
Response.write("<tr><td>" & rs.fields(1) & "</td><td>" & rs.Fields(2) & "</td><td>" & rs.Fields(3) & "</td><td>" & rs.Fields(4) & "</td></tr>")
rs.MoveNext
loop
rs.close
conn.close
%>
</table>


</body>
</html>


This is the error I am receiving when I click the Submit button:


Microsoft VBScript compilation error '800a0401'

Expected end of statement

/page2.asp, line 25

dim filterString = Request.Form("flname")
-----------------^

Can anyone help me please?

Old Pedant
04-01-2009, 03:18 AM
VBScript does *NOT* allow you to both DIM a variable and assign to it in one statement.

You can either do:

Dim filterString
filterString = Request.Form("flname")

or, if you really want to do it all on one line

Dim filterString : filterString = Request.Form("flname")


NOTE: An error message that says "compilation error" means you have an error in your syntax. Your code can't even *begin* to actually run until all compilation errors are corrected.

Iconoclast
04-01-2009, 03:20 AM
Ahhh, I was wondering about that, and I actually thought about putting the assignment statement on it's own below the variable declaration like your first example, but then I thought it couldn't be such a simple fix. I will that and post back if I have any other issues...thanks! :D

Iconoclast
04-01-2009, 03:42 AM
Okay, well I've tried to implement a way so that I could sort records either by ASC or DESC, but I can't seem to figure out how to do it...I've looked at a few resources online, but I've tried different ones and they haven't worked for me (mainly because I'm also using the filter, but I need both on the page). Can anyone help me? :/

Old Pedant
04-01-2009, 08:43 AM
Oh, adding the "filter" (as you call it) into *MY* example of sorting is easy!

Just add a hidden form field, like this:

<form ... >
<input type=hidden name="flname" value="<%=Request("flname")%>">
...

So that you will keep passing the filter string along from one page to the next.

If you look at the source code for my demo:
http://www.clearviewdesign.com/Newbie/Demos/ServerSideSort.asp

You will see that I always submit a <FORM> to carry the sorting info along:

<FORM Name="HiddenForm" Method="Post">
<INPUT Type=Hidden Name="SortBy">
<INPUT Type=Hidden Name="SortMsg">
<INPUT Type=Hidden Name="SortColumn">
<INPUT Type=Hidden Name="PriorSortBy" Value="<% = priorOrder %>">
</FORM>

<SCRIPT Language="JavaScript">
function goSort( fldName, headerText, columnNum )
{
theForm = document.HiddenForm;
theForm.SortBy.value = fldName;
theForm.SortMsg.value = headerText;
theForm.SortColumn.value = columnNum;
theForm.submit( );
}
</SCRIPT>

So if you just add one more hidden form field, your "flname" field, to that <form>, it should work!

You can see that I use the info from that hidden form to drive the SQL that is generated, and I end up doing:

SQL = "SELECT EmployeeName, Department, StartingDate, Salary " _
& " FROM Employees ORDER BY " & ordering

So you would just do something like

SQL = "SELECT your,list,of,fields FROM student " _
& " WHERE lname LIKE '" & filterString & "%' " _
& " ORDER BY " & ordering

Do *NOT* use SELECT *! Explicitly choose only the fields you intend to show.

Go look at my demo again and see if you can't adapt it, given this new info.

Iconoclast
04-01-2009, 09:36 PM
Okay, I looked at the code you gave me, as well as the source from that page...and it looks really interesting, and I tried to follow everything that was happening and what each part does (your comments are very useful!), but I still can't seem to figure out what I need to use along those lines to make mine work.

The first thing I'm a bit confused about is the very first thing you said, about using a hidden input for the filter...does that mean I can replace my entire filter section (I have a form that does it, which submits to page2.asp on submit), with what you posted? But even then that doesn't make sense to me because won't the user still need some way to initiate the sort (a button?)?

I think the issue I'm having with the rest of it is that there's just an overwhelming amount of code in the source to look at and try to figure out what each part is doing, and which parts I need to use for mine...your example is really good, don't get me wrong, I just don't think I have the level of knowledge yet that I need to figure out what I need to do to implement a sort =/

I fixed the issue you mentioned at the bottom, replacing * with the specific fields I want to use (fname, lname, studentnum, bod).

Old Pedant
04-01-2009, 09:52 PM
You would normally *still* use a separate page to get things started. That is, to pick the initial filter.

And if that initial page passes the filter by using something like

Enter the name here: <input name="flname">

or maybe

Choose a name:
<select name="flname">
<option>whatever</option>
...
</select>

Then the first time on the page indeed when you do

filterString = Request("flname")

you will be getting the value from the prior page.

If you now *copy* that value into the hidden form field, as I showed:

<input type=hidden name="flname" value="<%=flname%>">
or even
<input type=hidden name="flname" value="<%=filterString%>">

then on all SUBSEQUENT hits to the page--caused by the user choosing a different sort order--your code that does

filterString = Request("flname")

will *STILL* get the right value!

If you want, send me the code for your two pages along with the ".mdb" file. ZIP them all up and send to
asp ATSIGN juncojunction PERIOD com

Iconoclast
04-01-2009, 10:12 PM
Hmmm, but I'm still stuck on the same thing...won't the user still need a button of some sort to initiate the filter? Otherwise won't it filter automatically or something?

I zipped the 3 files together (page1.asp, page2.asp, testdb.mdb) and emailed them to you...thanks a lot for your help! :D

Iconoclast
04-02-2009, 01:55 AM
I can't thank you enough mate, it works perfectly...I'm going to have to spend some time looking over what you did to figure out what each part is doing, but I think I will be able to manage...thanks again for all your help, very impressive! :D

Iconoclast
04-02-2009, 08:37 AM
Okay, now that I've got that down, let's say I want to make it a bit more complex, to allow users to be able to create/modify/delete records in the database.

So, the first thing I'd like to be able to do is to allow a user to create a record...so I'd have 4 textboxes (firstname, lastname, studentnumber, dateofbirth), and a button that would submit to a page displaying the newly added record...I think I can probably figure that part out on my own, but I think I'll need help with the next parts:

Let's say I want to add another column to the table, which contains buttons that will allow the user to delete that specific row (the buttons would be linked to their respective rows by their row ID). This part I might be able to do as well, I'm planning to look into it tomorrow.

The last thing I'd like to do (probably what I'll need the most help with, although I don't think it's very different from the delete buttons) is to add yet another column to the table, again containing buttons linked to each respective record by row ID, but these buttons would load the record data into controls that will allow the user to modify the data...once the users have made changes and are done, have another button submit back to a page with an update query on the table, which will display the updated records for the specific row they just changed (as well as the other rows too, of course).

Can you help me out with this? I appreciate all the help you've been giving me! :D

Like I said, I think I can probably figure out the first two parts on my own looking at other examples and tutorials on the internet, but I think I'll definitely need help for the third part...any help would be greatly appreciated...I will post back if I manage to get any of the other sections working in the meantime.

whammy
04-02-2009, 09:05 AM
That should be fairly simple, just form posts and specific data requests. I used to do this exact kind of stuff all the time so post if you need more help.

I'd like to refresh my brain on this stuff since I've been out of it now for a few years. ;)

Old Pedant
04-02-2009, 09:09 AM
Actually, you can use the *EXACT SAME* <form> to enter a NEW record as you use to EDIT and existing record!

And the code that processes the <FORM> only needs a couple of conditional lines to allow it to do BOTH operations! Yes, with 90%+ the same code.

Create your INSERT <form> first & get it working and then we can show you how to use it for EDIT as well.

Note: Look into using ADODB.Recordset.AddNew to add the new records, rather than using raw SQL. Not mandatory, but it makes the combined add/edit process a LOT easier!

Iconoclast
04-02-2009, 09:31 AM
Okay, well the first thing I've tried to do so far is allow users to add a record to the database...it seemed easy at first, but now I think I've run into a bit of a wall. I'm using the Add Record tutorial from w3schools.com (linky link (http://www.w3schools.com/ado/ado_add.asp)), and so far here's what my two pages look like:

page1.asp

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Testing ASP with SQL</title>

</head>

<body bgcolor="#a9a9a9">

<br /><br /><br />

<p align="center">ASP + SQL</p>

<br /><br /><br />

<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("mytestdb.mdb"))

set rs = Server.CreateObject("ADODB.recordset")
rs.Open "SELECT fname, lname, studentnum, bod FROM student", conn
%>

<table border="1" width="100%">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Student Number</th>
<th>Date of Birth</th>
</tr>
<%
do until rs.EOF
Response.write("<tr><td>" & rs.fields(0) & "</td><td>" & rs.Fields(1) & "</td><td>" & rs.Fields(2) & "</td><td>" & rs.Fields(3) & "</td></tr>")
rs.MoveNext
loop
rs.close
conn.close
%>
</table>

<br /><br /><br />

<strong>Add a new record to the database:</strong><br /><br />

<form name="addRecord" action="page2add.asp" method="post">

<table border="0" width="25%">
<tr>
<th>Field</th>
<th>Data &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
</tr>
<tr>
<td>First Name</td>
<td><input type="text" name="firstname" /></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type="text" name="lastname" /></td>
</tr>
<tr>
<td>Student Number</td>
<td><input type="text" name="studentnumber" /></td>
</tr>
<tr>
<td>Date of Birth</td>
<td><input type="text" name="dateofbirth" /></td>
</tr>
</table>
<input type="submit" value="Add This Record!" />
<input type="reset" value="Clear" />

</form>


</body>
</html>


page2add.asp:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>(ADD RECORD)</title>

</head>

<body bgcolor="#a9a9a9">

<br /><br /><br />

<p align="center">ASP + SQL</p>

<br /><br /><br />

<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("mytestdb.mdb"))

sql="INSERT INTO student (fname,lname,"
sql=sql & "studentnum,dob)"
sql=sql & " VALUES "
sql=sql & "('" & Request.Form("firstname") & "',"
sql=sql & "'" & Request.Form("lastname") & "',"
sql=sql & "'" & Request.Form("studentnumber") & "',"
sql=sql & "'" & Request.Form("dateofbirth") & "')"

on error resume next
conn.Execute sql,recaffected
if err<>0 then
Response.Write("No update permissions!")
else
Response.Write("<h3>" & recaffected & " record added</h3>")
end if
conn.close

%>
</table>

</body>
</html>


Three things:

1) I noticed on the W3 tutorial they say that if the table contains a primary key, you need to append an incrementing number for this field for each record added...my database has a primary key column, but it is the default ID column that was created when I made the table (there is a studentnum column, but these are random, non-sequential numbers and therefore not ideal for a PK column). So I'm not exactly sure if that's something I'll need to do for this to work or not, I'm hoping someone can tell me if that is the case, and if so, how I would do it.

2) I'm using a total of 4 columns: 2 are text (fname, lname), 1 is integer (studentnum), and the other is date/time (dob). It occurs to me that for users adding a new record, the data they input for the student number and date of birth fields must be somehow converted to that datatype, correct? Can someone tell me or show me how this is done?

3) I'd also like to implement some function that will check to validate the data in the textbox fields...in other words, if they are empty (ie user left it blank by accident), the wrong data type (ie text where it should be an integer), or invalid data/format (ie invalid date format) display a popup alert containing a message with such info (so they can fix it).

I'd also like to point out that with the two pages I've posted above, when I run the code myself and try to add a record, even though I have not yet implemented any of the above things I've mentioned, it gives me an error on the submit page that says "No update permissions!"...I realize the code I've used from the W3 tutorial is what causes this message to be displayed, but I'm wondering how I fix whatever permissions issue exists in order to be able to at least write to the database? Thanks for the help! :D

whammy
04-02-2009, 10:20 AM
Old Pedant, could you possibly give some examples of how using "ADODB.Recordset.AddNew" would be desirable?

I never had the necessity to use it in the past, but I am always open to learning new things... and looking it up, I can't think of any scenarios where I'd have to use it. I am a bit sleepy though. ;)

Iconoclast
04-02-2009, 10:23 AM
Note: Look into using ADODB.Recordset.AddNew to add the new records, rather than using raw SQL. Not mandatory, but it makes the combined add/edit process a LOT easier!

Sorry, I didn't actually see this until just now...

I found this tutorial (http://www.w3schools.com/ado/met_rs_addnew.asp) on W3 about the AddNew method for the RS.

If I were to use that, how exactly would I do it? I mean, this is the code provided in the example:

<%
rs.AddNew "ProductName","Chang"
%>

or

<%
varfields=Array("ProductName","Prize","Quantity")
varvalues=Array("Chang","19","24-12 oz bottles")
rs.AddNew varfields,varvalues
%>


But how would that work with my database, where I've got multiple fields/columns that need to have data in order to add the record?

whammy
04-02-2009, 10:36 AM
Oh that's slick... I'll mess with this tomorrow, if I can get my test database set up on my comp then.

You gotta love w3schools.com...

Old Pedant
04-02-2009, 10:56 PM
Okay....long reply...

Assumption: Database with table named "students".
Fields are id, name, phone, email
id is an autonumber (identity in SQL Server) field.

First, let's say I have a page where you can choose an existing student to edit or you can choose to add a new student. Maybe something simple like this:

***** FILE: chooseStudent.asp *******

<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "....your connection string..."

SQL = "SELECT id, name FROM students ORDER BY name"
Set RS = conn.Execute( SQL )
%>
<table border=1>
<%
Do Until RS.EOF
%>
<tr>
<td><form action="addEdit.asp" method=post style="display: inline;">
<input type=hidden name="id" value="<%=RS("id")%>">
<input type=submit value="EDIT">
</form></td>
<td><%=RS("name")%></td>
</tr>
<%
RS.MoveNext
Loop
%>
<tr>
<td colspan=2><hr></td>
</tr>

<tr>
<td><form action="addEdit.asp" method=post style="display: inline;">
<input type=hidden name="id" value="-1">
<input type=submit value="ADD">
</form></td>
<td>Add a new student</td>
</tr>
</table>


That page, one way or the other, posts to this next page. Note that if you are adding a student, it passes -1 for the ID!!

********** FILE: addEdit.asp ***********

<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "....your connection string..."

id = -1
On Error Resume Next
id = CINT( Request("id"))
On Error GoTo 0
' assume a new student:
name = ""
phone = ""
email = ""

SQL = "SELECT * FROM students WHERE id = " & id
Set RS = Conn.Execute(SQL)

If Not RS.EOF Then
name = RS("name")
phone = RS("phone")
email = RS("email")
End If
RS.Close
Conn.Close
%>
<form action="Save.asp" method=post>
<input type=hidden name="id" value="<%=id%>">
Name: <input name="name" value="<%=name%>">
Phone: <input name="phone" value="<%=phone%>">
EMail: <input name="email" value="<%=email%>">
<input type=submit value="Save!">
</form>


See that? If we have the ID for an existing studend, then the editiable fields are filled in with the existing values. If not, the editable fields will be blank.

So then that page always posts to:

********** FILE: Save.asp ************

<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "....your connection string..."

id = -1
On Error Resume Next
id = CINT( Request("id"))
On Error GoTo 0

SQL = "SELECT * FROM students WHERE id = " & id
Set RS = Server.CreateObject("ADODB.RecordSet")
RS.Open conn, SQL, 3, 3 ' adOpenStatic, adLockOptimistic

If RS.EOF Then RS.AddNew
RS("name") = Request("name")
RS("phone") = Request("phone")
RS("email") = Request("email")
RS.Update

Response.Write "Saved information about student " & RS("id")

RS.Close
Conn.Close
%>

Voila!

See then sneaky trick? We open the table and, if the id passed was -1, we won't get any record. BUT WE WILL GET THE STRUCTURE OF THE TABLE! So then if we don't have a record, we do ADDNEW. And now we DO have a "current record."

So we change the existing record or put values into the newly created one and do the update. And note the last little sneaky bit: If you go get the ID value *after* the UPDATE, then you will have the autonumber (identity) value of the student, even if it's a new record!

So THIS is what I mean by being able to use ADDNEW and write code that does either edit or add.

Okay?

Iconoclast
04-09-2009, 09:17 AM
Hey OldPedant, sorry for the delay I ended up having to take a week or so off school because my sister was in a pretty bad car accident and I spent most of the time in the hospital...but she's doing okay now :)

Anyways I finally managed to come back and find your post, I want to thank you again for your help...once again, you've shown me something that I never would have thought of.

The last and final thing I would like to do with this page, is to also have Delete buttons that I could put in the table beside the Edit button column, that would allow a user to delete that row from the database. Can you give me an idea of how this would be accomplished using the code you already provided me with?

Thanks again for all your help mate, I really appreciate it! :D

Old Pedant
04-10-2009, 07:14 AM
DELETE is the most trivial operation of all.

I don't know what your <TABLE> looks like, so making a sweeping statement about how to do the DELETE is tough.

In many pages, I have actually used separate <FORM>s for each EDIT and for each DELETE:

<table>
<% Do Until RS.EOF %>
<tr>
<td><form action=edit.asp method=post>
<input type=hidden value="<%=RS("id")%>">
<input type=submit value="EDIT">
</td>
<td><form action=delete.asp method=post>
<input type=hidden value="<%=RS("id")%>">
<input type=submit value="DELETE">
</td>
<td><%=RS("name")%></td>
... other fields
</tr>
<%
RS.MoveNext
Loop
%>
</table>

But if you have <input type=text> fields in your rows and allow inplace editing, this may not be practical.

So show me the general flow of your table/page.

As for doing the delete:

<%
Set conn = ....
conn.Open

SQL = "DELETE FROM table WHERE id = " & Request("id")
howmany = -1
conn.Execute SQL howmany
If howmany <> 1 Then
Response.Write "Oops..." & howmany & " records deleted."
Response.End
End If
...
%>


Typically, I submit the DELETE form to a hidden <IFRAME> on the same page and then have the iframe use JS code to refresh the main page.

Iconoclast
04-13-2009, 06:28 AM
When I try to add a new student, I receive the following error on the save.asp page (once you click the Save button on the addedit.asp page):

ADODB.Recordset error '800a0bb9'

Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

/save2.asp, line 30

Line 30 is this:


RS.Open conn, SQL, 3, 3 ' adOpenStatic, adLockOptimistic



What does this mean and how do I fix it? Thanks!

Old Pedant
04-13-2009, 11:21 PM
Probably means the your conn is not a valid already-open connection object or connection string. It *could* mean that your SQL is NULL, I suppose, but usually that gives a different error.

Iconoclast
04-13-2009, 11:31 PM
What exactly does this line mean:

RS.Open conn, SQL, 3, 3 ' adOpenStatic, adLockOptimistic

I mean, I know what adOpenStatic and adLockOptimistic are, although they're commented out...but what is the 3, 3 bit?

Old Pedant
04-14-2009, 07:08 AM
The first 3 *is* actually adOpenStatic

The second 3 *is* actually adLockOptimistic

If you haven't defined thos adXXX values either by #including adovbs.inc or by getting the meta info from the ADO DLL, you just use the actual numbers instead.

In other words, the ADOVBS.INC file has a couple of lines that look like
CONST adOpenStatic = 3
CONST adLockOptimistic = 3


Many of us get sloppy and just use 3,3 as a shortcut. For shame.

Iconoclast
04-14-2009, 07:55 AM
Couldn't I use/execute an SQL UPDATE query for the save instead of it submitting to a separate save.asp page?

This was my original plan: use an UPDATE query for Edit, and an INSERT query for Add...would that work?

Old Pedant
04-14-2009, 09:51 PM
Of course. And, generally, that's preferable. I was just showing other possibilities.