If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Updating db

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-10-05, 17:52
RippleSpas RippleSpas is offline
Registered User
 
Join Date: Jan 2005
Posts: 2
Question Updating db

Hi

I am quite new to ASP and cannot get a form to update my db.

I can retrieve and display the data, but I cannot add or edit.

I have a form that calls a Javascript to validate the data, I then want to set the fields to the new values entered, but I am clearly doing something wrong and it probably very simple! I suspect I cannot use this code from within the Javascript, but I cannot work out how to call from the submit button, then validate the data and then save the record.

I have included a simplified code and removed the add functionality, hopefully this demostrates what I am foolishly trying to do!:

function f_Submit(sAction){
var strValid;
strValid = "";

if ( document.frmCAFDel.Column1.value == "") {
strValid = "Column 1 cannot be blank.\n";
}

if (strValid == "") {
return true;
}
else {
alert(strValid);
return false;
}

<%
strSql = "SELECT * FROM MYTABLE WHERE MYKEY = '" & strMyKey & ";"

Set rsDD = Server.CreateObject("ADODB.Recordset")
rsDD.Open strSql,objConn,adOpenForwardOnly,adLockOptimistic, adCmdText

if not rsDD.BOF and not rsDD.EOF then
rsDD.MoveFirst
rsDD("column1") = strColumn1
rsDD.Update
end if

' Close rs.
rsDD.Close
Set rsDD = Nothing
%>

window.document.frmCAFDel.action = sAction;
window.document.frmCAFDel.submit();
}

Help me please.....
Reply With Quote
  #2 (permalink)  
Old 03-10-05, 18:03
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
Generally people avoid doing what you are trying to do, eg. grab a recordset and use the recordset update method to change data.

What most people will do is create a sql update statement to do the same job, so something like....
Code:
<%
strColumn1 = Request.Form("Column1")

if strColumn1<>"" then
  strsql="Update myTable set column1='" & strColumn1 & ' where mykey = '" & strMyKey & ";"
  objConn.Execute(strSql)
end if 

%>
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On