Results 1 to 2 of 2

Thread: Updating db

  1. #1
    Join Date
    Jan 2005

    Question Unanswered: Updating db


    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 {
    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("column1") = strColumn1
    end if

    ' Close rs.
    Set rsDD = Nothing

    window.document.frmCAFDel.action = sAction;

    Help me please.....

  2. #2
    Join Date
    Nov 2003
    Christchurch, New Zealand
    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....
    strColumn1 = Request.Form("Column1")
    if strColumn1<>"" then
      strsql="Update myTable set column1='" & strColumn1 & ' where mykey = '" & strMyKey & ";"
    end if 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts