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

Update empty fields with asp and access2000

Status
Not open for further replies.

Smarty

Programmer
Apr 12, 2001
191
0
0
BE
I have the following problem. Through my asp page I want to update a record, but when a field is originally empty, the update don't work...

any1 knows this problem and has an answer?

Thx,

Smarty
 
If I understand you correctly...I have this problem whether I use asp or vba. Unless Access already has a record in the table, you cannot insert new ones. My solution has always been to add a bogus record in the table and then all will proceed normally. I have see MS Access (from Microsoft) sample databases do the same thing. I don't know if this is the best solution, but it works.
 
You should know if the record is new or an old one being edited based on your process flow. If it is new you must send an INSERT statement to Access. If it is being edited then you will send an UPDATE statement.

If for some reason you don't know ahead of time if the record is new or not then you could always query the database for the record. If it is found then run your UPDATE. If it is not found then run your INSERT.

Hope this helps. Wushutwist
 
Regurgitating what Wushutwist said,

You can not update a record that does not exist. The command will simply be executed and effect 0 records.

You can check how many records were affected by assigning a variable to the second argument of the execute method of a connection object :
<%
Dim lAffected
Dim oCon
Set oCon = Server.CreateObject(&quot;ADODB.Connection&quot;)
oCon.Execute(&quot;Update tblFood Set bYummy = 1 Where idFood = 99&quot;, lAffected)
%>
 
update must work in asp even ur field is empty.if u dont mine please send ur code to me.i think its will be the sql query error.
with regards
webspy(raghuram23@hotmail.com)
 
I'm sure the record exists, and it doesn't give any problem when the field isn't empty but can just be changed. It does give errors when it is empty (or null). Here is (part of)the code:

dim conn
dim rs
Set Conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
' conn.close
Conn.Open &quot;DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=&quot; & Server.MapPath(&quot;Data\products.mdb&quot;)

dim ben
ben = replace(request(&quot;enbody&quot;),&quot;'&quot;,Chr(17))

if request(&quot;enbody&quot;) <> rs.fields(&quot;enbody&quot;) then

set rs2 = conn.execute(&quot;UPDATE promotions set enbody = '&quot; & ben & &quot;' where ID_Nieuws = &quot; & request(&quot;ID&quot;) & &quot;;&quot;)
end if

I hope this is more clearly...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top