« Previous Next »

Thread: unable to insert

Last post 01-05-2009 11:11 AM by tomkmvp. 7 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (8 items)

Sort Posts:

  • 01-05-2009, 5:37 AM

    • rajar32
    • Not Ranked
    • Joined on 09-13-2008, 4:11 AM
    • Posts 5

    unable to insert

     am trying to insert id to the statustable but i cannot able to add

    getting stuck with this error./.

    Type mismatch: 'sd'


    <%
    id = session("userid")
     sSql =  "SELECT  name   FROM nametable WHERE userID = "&id&""
    if request.form("submit")="Hide" then
    i=0
    elseif request.form("submit")="Show" then
    i=1
    end if
    sd= "select id from nametable where userid="&userid&""
    'oConn.Execute("UPDATE statustable SET status='"&i&"','"&sd(0)&"' WHERE userID = "&id&"")
     set msg=oConn.Execute("insert tbl1 (real,resid,userid) values ('"&i&"','"&sd(0)&"',"&userid&"")
        oRs.Open sSql, oConn
         While not oRs.EOF
              Response.write("<table cellspacing='1' cellpadding='4' class='rep_tbl'><tr><form method='post' ><td width='10%' align='right'>Name : </td><td width='30%'>"&ors(1)&"</td></tr><td align='right'><input name='submit'  type='submit' value='Hide' >  <input name='submit' type='submit' value='Show' ></td></form></tr></table>")
              oRs.MoveNext()
          Wend              
    end if  
    %>

  • 01-05-2009, 8:30 AM In reply to

    • tomkmvp
    • Top 10 Contributor
    • Joined on 03-20-2003, 10:27 AM
    • Central NJ
    • Posts 6,233
    • IIS MVPs

    Re: unable to insert

    On one line you have:

    sd= "select id from nametable where userid="&userid&""

    Then later you use:

    set msg=oConn.Execute("insert tbl1 (real,resid,userid) values ('"&i&"','"&sd(0)&"',"&userid&"") 

    This does not make any sense!

  • 01-05-2009, 8:59 AM In reply to

    • rajar32
    • Not Ranked
    • Joined on 09-13-2008, 4:11 AM
    • Posts 5

    Re: unable to insert

     hi,plzz...ignore my previous code...this is the code ...right now ...
    i need to check that if name_id is already der or not..if its der ... i need to update otherwise i need to insert....

    i get this error.....
    Error Type:
    Microsoft OLE DB Provider for SQL Server (0x80040E14)
    Line 1: Incorrect syntax near '1232'---------------> this is the value of useridof this line(oConn.Execute("insert statustable (status,name_id,userid) values ('"&i&"','" &request.form("nameid")&"',"&userid&"")).
    /bench_task/responses/hideshow.asp, line 134

    <%
    id = session("userid")
     sSql =  "SELECT  name,name_id   FROM nametable WHERE userID = "&id&""

     'set msg=oConn.Execute("insert tbl1 (satus,resid,userid) values ('"&i&"','"&sd(0)&"',"&userid&"")
        oRs.Open sSql, oConn
         While not oRs.EOF
              Response.write("<table cellspacing='1' cellpadding='4' class='rep_tbl'><tr><form method='post' ><td width='10%' align='right'>Name : </td><td width='30%'>"&ors(1)&"</td></tr><td align='right'><input type='hidden' name='nameid' value='"&ors(0)&"' ><input name='submit'  type='submit' value='Hide' >  <input name='submit' type='submit' value='Show' ></td></form></tr></table>")
              oRs.MoveNext()
          Wend              
    if request.form("submit")="Hide" then
    i=0
    elseif request.form("submit")="Show" then
    i=1
    end if
    set chk1 = oConn.Execute("select name_id from statustable where name_id='" &request.form("nameid")&"'")
    if not chk1.eof then
    oConn.Execute("UPDATE statustable SET status = '"&i&"',name_id= '" &request.form("nameid")&"'  where userID = "&userid&"")
    else
    oConn.Execute("insert statustable (status,name_id,userid) values ('"&i&"','" &request.form("nameid")&"',"&userid&"")
    end if
    %>

  • 01-05-2009, 9:15 AM In reply to

    • tomkmvp
    • Top 10 Contributor
    • Joined on 03-20-2003, 10:27 AM
    • Central NJ
    • Posts 6,233
    • IIS MVPs

    Re: unable to insert

    So you want to have this SQL:

    insert statustable (status,name_id,userid) values ('i','nameid',userid) 

    where status and name_id are strings and userid is a number.  So this would then be the proper code:

    oConn.Execute( "insert statustable (status,name_id,userid) values ('" & i & "','" & Request.Form("nameid") & "', " & userid & ")" )

  • 01-05-2009, 9:32 AM In reply to

    • rajar32
    • Not Ranked
    • Joined on 09-13-2008, 4:11 AM
    • Posts 5

    Re: unable to insert

     ya i can able to insert ..but if i load the page again ...my db of name_id is changing to zero .or if i refresh the page ,,,or try to insert any other name_id.....
    how can i hold it permanently....so that specific name_id ll  exists untill i cahnge....

    <%
    id = session("userid")
     sSql =  "SELECT  name,name_id   FROM nametable WHERE userID = "&id&""

     'set msg=oConn.Execute("insert tbl1 (satus,resid,userid) values ('"&i&"','"&sd(0)&"',"&userid&"")
        oRs.Open sSql, oConn
         While not oRs.EOF
              Response.write("<table cellspacing='1' cellpadding='4' class='rep_tbl'><tr><form method='post' ><td width='10%' align='right'>Name : </td><td width='30%'>"&ors(1)&"</td></tr><td align='right'><input type='hidden' name='nameid' value='"&ors(0)&"' ><input name='submit'  type='submit' value='Hide' >  <input name='submit' type='submit' value='Show' ></td></form></tr></table>")
              oRs.MoveNext()
          Wend              
    if request.form("submit")="Hide" then
    i=0
    elseif request.form("submit")="Show" then
    i=1
    end if
    set chk1 = oConn.Execute("select name_id from statustable where name_id='" &request.form("nameid")&"'")
    if not chk1.eof then
    oConn.Execute("UPDATE statustable SET status = '"&i&"',name_id= '" &request.form("nameid")&"'  where userID = "&userid&"")
    else
    oConn.Execute( "insert statustable (status,name_id,userid) values ('" & i & "','" & Request.Form("nameid") & "', " & userid & ")" )
    end if
    %>

  • 01-05-2009, 10:28 AM In reply to

    • tomkmvp
    • Top 10 Contributor
    • Joined on 03-20-2003, 10:27 AM
    • Central NJ
    • Posts 6,233
    • IIS MVPs

    Re: unable to insert

    <input type="hidden" name="nameid" value="<%= Request.Form("nameid") %>" />

  • 01-05-2009, 10:40 AM In reply to

    • rajar32
    • Not Ranked
    • Joined on 09-13-2008, 4:11 AM
    • Posts 5

    Re: unable to insert

    gettin this error,

    Invalid character

     

     Response.write("<table cellspacing='1' cellpadding='4' class='rep_tbl'><tr><form method='post' ><td width='10%' align='right'>Name : </td><td width='30%'>"&ors(1)&"</td></tr><td align='right'><input type='hidden' name='nameid' value="<%= Request.Form("nameid") %>" ><input name='submit'  type='submit' value='Hide' >  <input name='submit' type='submit' value='Show' ></td></form></tr></table>")

  • 01-05-2009, 11:11 AM In reply to

    • tomkmvp
    • Top 10 Contributor
    • Joined on 03-20-2003, 10:27 AM
    • Central NJ
    • Posts 6,233
    • IIS MVPs

    Re: unable to insert

    If you're using Response.Write then it would be ...

    <input type='hidden' name='nameid' value='" & Request.Form("nameid") & "' >

Page 1 of 1 (8 items)
Microsoft Communities