|
 |
asp_web_howto thread: Re: Update on empty recordset
Message #1 by Imar@S... on Thu, 13 Jun 2002 20:02:12
|
|
Hi there,
No this won't work. Setting values the way you do will only work on a
current record, which obviously isn't present when EOF is true.
You can either use AddNew which creates a new record (not really
recommended) or use an SQL INSERT statement to insert a new record.
The problem with the AddNew method is that it doesn't work with a
firehose (forward only read only) recordset which usually is the fastest
way to get at the data.
Personally I'd do something like this:
If rsTest.EOF Then
Dim sSQL
sSQL = "INSERT INTO MyTable (Field1, Field2) VALUES('" sField1
& "', '" & sField2 & "'"
' The following line assumes the connection is still open
objConnection.Execute(sSQL)
Else
' Do whatever you need to do with the rs
End If
HtH
Imar
> I'm curious, if I created a recordset like so:
oRs.Open "Select * from MyTable where MyKey=3D" & MyKey,,2,3
Then afterwards, regardless of the EOF status of the recordset, I did
something like this.
oRs("Field1") =3D Field1
oRs("Field2") =3D Field2
oRs("Field3") =3D Field3
oRs.Update
Now, say MyKey is an Identity field, and also say that .EOF was True.
Would this transaction create a new record? If so, is there a property
of the recordset that I can set to only allow updates to existing
records, and throw an error if .EOF was true when I started updating
things. I know I could encapsulate the Update stuff in an If Not
oRs.Eof statement, but pretend I can't do that.
Thanks,
Jerry
Message #2 by "Jerry Diegel" <diegelj@g...> on Thu, 13 Jun 2002 11:50:10 -0500
|
|
I'm curious, if I created a recordset like so:
oRs.Open "Select * from MyTable where MyKey=3D" & MyKey,,2,3
Then afterwards, regardless of the EOF status of the recordset, I did
something like this.
oRs("Field1") =3D Field1
oRs("Field2") =3D Field2
oRs("Field3") =3D Field3
oRs.Update
Now, say MyKey is an Identity field, and also say that .EOF was True.
Would this transaction create a new record? If so, is there a property
of the recordset that I can set to only allow updates to existing
records, and throw an error if .EOF was true when I started updating
things. I know I could encapsulate the Update stuff in an If Not
oRs.Eof statement, but pretend I can't do that.
Thanks,
Jerry
P.S. This may be a duplicate send. Lyris just sent me a message saying
I tried to post an attatchment to the list. I checked, I didn't, but
what the hey. A little list clutter never killed anyone:)
|
|
 |