1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

New Programmer struck with similar Problem- ADO Update

Discussion in 'C#' started by cgo991, Sep 25, 2006.

  1. #1
    Hi All,

    I have encountered problem with form submission again when inserting data to database via form. The error msg is below:

    error '80004005'
    Unspecified error

    /MassReg/AddSession.asp, line 244


    Problem is at this line:
    rs.open "select * from Session",conn,1,3

    Pls see the code attached

    My Database is:
    BRANCH_name=Text
    Year=Text
    BLK=Text
    SessionLevel=Text
    TimeFrom=Text
    TimeTo=Text

    The strange thing is it work for another form but not this form.
    Is that something wrong with my coding?
    Pls help..
     

    Attached Files:

    cgo991, Sep 25, 2006 IP
  2. Free Born John

    Free Born John Guest

    Messages:
    111
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    ok,

    first-off you ought to reorganise the code.

    Put the failing stuff into a sub called doAdd or whatever and at the start of your page have

    if Request.QueryString("add")="yes" then
    doAdd
    response.redirect("backtowhereicamefrom.asp")
    end if

    That way you're not rewriting the whole page for an update. Then again you might want to do that, your choice. It would also be better used to use a hidden field and request.form("add") as it's marginally more secure.

    I would guess the sql error is related to your already having used the connection. Try closing and then reopening it, or establish a second connection. Or just follow the advice above and it won't already have been used.
     
    Free Born John, Sep 25, 2006 IP
  3. cgo991

    cgo991 Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi All,

    As advised I have add in the code into subroutine but it still show error in
    rs.open "select * from Session",conn,1,3

    I wonder where go wrong? The problem is sometime it will work in this form but as I create another similar form, it doesn't..

    Pls help thks
     
    cgo991, Sep 25, 2006 IP
  4. shaileshk

    shaileshk Well-Known Member

    Messages:
    455
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #4
    you need to update your self bcz you dont have basic knowlage of asp pls read any fundamental book of asp
     
    shaileshk, Sep 26, 2006 IP
  5. Free Born John

    Free Born John Guest

    Messages:
    111
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    perhaps you could enlighten us all by explaining what the basic error is then
     
    Free Born John, Sep 26, 2006 IP
  6. shaileshk

    shaileshk Well-Known Member

    Messages:
    455
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #6
    i have already given add code for that now you would like to edit record

    when you are update code add that time you need 1 unique record id(primary key )

    save primary key value in hidden textbox when you submit button press at that time primary value also pass

    you get primary key value

    id=request("id")

    if id="" then
    id=-1
    end if
    rs.open "select * from tblName where id="&id&"
    if id<>"" then

    else
    rs.addnew
    end if
    rs("fildname")=values
    rs("fildname")=values
    rs("fildname")=values
    rs("fildname")=values
    rs.update

    rs.close
     

    Attached Files:

    shaileshk, Sep 27, 2006 IP
  7. Free Born John

    Free Born John Guest

    Messages:
    111
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    very interesting but I don't see the relevance to the problem at hand.

    "select * from Session" is just as valid as "select * from Session where id = 123"

    The question is, why is that sql throwing an error.
     
    Free Born John, Sep 27, 2006 IP
  8. shaileshk

    shaileshk Well-Known Member

    Messages:
    455
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #8
    In this example we are using ADO to update an existing record. The SQL statement is the key and by changing that you can update whatever record you want to.

    This is just an example to get you started.
    
    <% ID = 7 %>
    <% NAME = "Joe Smoe" %>
    <% MESSAGE = "This is another test" %>
    
    <% 
    ' declaring variables
    ' not neccesary but a good habit
    Dim DataConn
    Dim CmdUpdateRecord
    Dim MYSQL
        
    Set DataConn = Server.CreateObject("ADODB.Connection")
    Set CmdUpdateRecord = Server.CreateObject("ADODB.Recordset")
        
    ' The line below shows how to use a system DSN instead of a DNS-LESS connection
    ' DataConn.Open "DSN=System_DSN_Name"
    DataConn.Open "DBQ=" & Server.Mappath("../_database/database.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};"
        
    MYSQL = "SELECT some_table.* FROM some_table WHERE (ID = " & ID & ")"
        
    CmdUpdateRecord.Open MYSQL, DataConn, 1, 3
        
    CmdUpdateRecord.Fields("NAME") = NAME
    CmdUpdateRecord.Fields("MESSAGE") = MESSAGE
    CmdUpdateRecord.Update
        
    ' closing objects and setting them to nothing
    ' not neccesary but a good habit
    CmdUpdateRecord.Close
    Set CmdUpdateRecord = Nothing
    DataConn.Close
    Set DataConn = Nothing
    %>
    
    
    Code (markup):
    http://www.powerasp.com/content/database/default.asp try this link for add update and delete record
     
    shaileshk, Sep 27, 2006 IP