Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 9th, 2004, 03:09 AM
Authorized User
 
Join Date: Oct 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default Update query

Hi, I have a update query thats works fine when I use characters value for POSTCODE. But in this query I wont to use a Integer value. The user update the value (POSTCODE) in a input box. The error message is like this

A value is not compatible with the data type of its assignment target. Target name is "POSTCODE". SQLSTATE=42821

A bit of my code is like this

vPOSTCODEn= "POSTCODE" & myRs.Fields("SAID")
vPOSTCODE= CInt(request.form("vPOSTCODEn"))

SQL="UPDATE TEST.Supplier SET SALECOMPANY= '" & vSALECOMPANY &"', SALECOMPANYNUMBER='" & vSALECOMPANYNUMBER & "', ADRESS='" & vADRESS & "', POSTCODE = " & vPOSTCODE & " , CITY = '" & vCITY & "',COUNTRY = '" & vCOUNTRY & "' WHERE SAID=" & vSAID


 
Old November 9th, 2004, 03:21 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Jonax
Default

If what you are trying to do is to Request the contents of a dynamically named form-field, then you might want to remove the quotes in the second line, like this:

Code:
vPOSTCODE= CInt(request.form(vPOSTCODEn))
 
Old November 9th, 2004, 03:29 AM
Authorized User
 
Join Date: Oct 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry, I wrote wrong in my last topic.

The code I´am using is
vPOSTCODE= CInt(request.form(vPOSTCODEn))

I think that I´am doing wrong when I put it in the SQL query? A integer dont need any ' ' so I took them out.

 
Old November 9th, 2004, 03:36 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Jonax
Default

Try checking what the SQL-string contains before executing it...

Code:
[...]
SQL="UPDATE TEST.Supplier SET SALECOMPANY= '" & vSALECOMPANY &"', SALECOMPANYNUMBER='" & vSALECOMPANYNUMBER & "', ADRESS='" & vADRESS & "', POSTCODE = " & vPOSTCODE & " , CITY = '" & vCITY & "',COUNTRY = '" & vCOUNTRY & "' WHERE SAID=" & vSAID 

Response.Write SQL
Response.End
[...]
 
Old November 9th, 2004, 03:57 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Jonax
Default

[quote]
...when I use characters value for POSTCODE...
[quote]

If the datatype of the field in the db is a string-type - you should pass it numeric postcodes as sting as well.
Try removing the cint() and (re)inserting the ''.

 
Old November 9th, 2004, 04:04 AM
Authorized User
 
Join Date: Oct 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I tried to write it out but still got the error message and nothing writes out on the screen.

In the error message I get this values
SAID1=1&SALECOMPANY1=a&SALECOMPANYNUMBER1=a&ADRESS 1=a&POSTCODE1=1&CITY1=a&COUNTRY1=a

I just put an a in all boxes that wants a charater and 1 for POSTCODE that wants a Interger to test. So the value comes with me but it´s the wrong datatype.

Error message
A value is not compatible with the data type of its assignment target. Target name is "POSTCODE".



 
Old November 9th, 2004, 04:10 AM
Authorized User
 
Join Date: Oct 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I got the same error message when I remove CInt() and put back the ''


 
Old November 9th, 2004, 06:10 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 345
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to gokul_blr Send a message via Yahoo to gokul_blr
Default

Can you check once with the table fields in the order from top whether you have given it in sequence.

or any mismatch between the query statement fields and table structure (position).


Gokulan Ethiraj
 
Old November 9th, 2004, 06:32 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Cilla,
Quote:
quote: I tried to write it out but still got the error message and nothing writes out on the screen.
That shouldn't be returning error unless you try to execute that on SQL server from your asp page. Did you try that exactly as Jonax has suggested? As Response.End stops executing the page at that point, you should be able to see how the UPDATE statement is constructed and also the values of each being passed to it.

It is better you post information on what is the datatype of POSTCODE in the table and what is the value you are passing for that.

This should let us understand better on what you are missing there.

Cheers!

_________________________
- Vijay G
Strive for Perfection
 
Old November 9th, 2004, 07:38 AM
Authorized User
 
Join Date: Oct 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, yes I did As Jonax wrote
The datatype of POSTCODE in the table is Integer.
I have just for a test, made it to Char in the database and then
the code is working fine. But no I have put it back to an Integer.

the part of my code thats include the Case Update.
Code:
Case "Uppdatera"

        Set myConn = Server.CreateObject("ADODB.Connection")
        myConn.Open "DSN=CPRCT;UID=" & session("anvid") & ";PWD=" & session("password") & ""

        Set myRs = Server.CreateObject("ADODB.Recordset")
        SQL = "SELECT * FROM TEST.Supplier"

         myRs.Open SQL,myConn,3,3 


    if len(Request.Form("btnval")) > 0 then
         While not myRs.EOF

         vSAIDn= "SAID" & myRs.Fields("SAID")
         vSAID= CInt(request.form(vSAIDn))

         vSALECOMPANYn= "SALECOMPANY" & myRs.Fields("SAID")
         vSALECOMPANY= CStr(request.form(vSALECOMPANYn))

         vSALECOMPANYNUMBERn="SALECOMPANYNUMBER" & myRs.Fields("SAID")
         vSALECOMPANYNUMBER= CStr(request.form(vSALECOMPANYNUMBERn))

         vADRESSn= "ADRESS" & myRs.Fields("SAID")
         vADRESS= CStr(request.form(vADRESSn))

         vCITYn="CITY" & myRs.Fields("SAID")
         vCITY= CStr(request.form(vCITYn))

         vCOUNTRYn="COUNTRY" & myRs.Fields("SAID")
         vCOUNTRY= CStr(request.form(vCOUNTRYn))

         vPOSTCODEn="POSTCODE" & myRs.Fields("SAID")
         vPOSTCODE= CInt(request.form(vPOSTCODEn))

        SQL="UPDATE TEST.Supplier SET SALECOMPANY= '" & vSALECOMPANY &"', SALECOMPANYNUMBER='" & vSALECOMPANYNUMBER & "', ADRESS='" & vADRESS & "', POSTCODE = "& vPOSTCODE &", CITY = '" & vCITY & "',COUNTRY = '" & vCOUNTRY & "' WHERE SAID=" & vSAID 
        Response.Write SQL
        Response.End

        myConn.Execute(SQL)
        myRs.MoveNext

         wend
    End if

             myRs.Close
             SQL = "SELECT * FROM TEST.Supplier"
             myRs.Open SQL,myConn,3,3



        %>
        <Form Method="Post" Action="Supplier.asp">
        <Table><TR><TD><B>Leverantörs id</b></TD><TD><b>Leverantörs namn</b></TD><TD><b>Leverantörs nummer</b></TD>
        <TD><b>Adress</b></TD><TD><b>Postnummer</b></TD><TD><b>Stad</b></TD><TD><b>Land</b></TD>
        <TD><b>Ta bort?</B></TD></TR>
        <%
         While not myRs.EOF
            %>
            <TR><TD><INPUT TYPE="text" name="SAID<%=myRs.Fields("SAID") %>" value="<%=myRs.Fields("SAID")%>" style="background:white;color:BLACK;font-family:arial, verdana; font-size:15px; height:25px;font-color:#ffff00;"
                                size="20"></TD>
            <TD><INPUT TYPE="text" name="SALECOMPANY<%=myRs.Fields("SAID") %>" value ="<%=myRs.Fields("SALECOMPANY")%>" style="background:white;color:BLACK;font-family:arial, verdana; height:25px;font-size:15px; font-color:#ffff00;"
                                size="20"></TD>
            <TD><INPUT TYPE="text" name="SALECOMPANYNUMBER<%=myRs.Fields("SAID") %>" value = "<%=myRs.Fields("SALECOMPANYNUMBER")%>" style="background:white;color:BLACK;font-family:arial, verdana; font-size:15px; height:25px;font-color:#ffff00;"
                                size="20"></B></TD>
            <TD><INPUT TYPE="text" name="ADRESS<%=myRs.Fields("SAID") %>" value="<%=myRs.Fields("ADRESS")%>" style="background:white;color:BLACK;font-family:arial, verdana; font-size:15px; height:25px;font-color:#ffff00;"
                                size="20"></TD>
            <TD><INPUT TYPE="text" name="POSTCODE<%=myRs.Fields("SAID") %>" value ="<%=myRs.Fields("POSTCODE")%>" style="background:white;color:BLACK;font-family:arial, verdana; height:25px;font-size:15px; font-color:#ffff00;"
                                size="20"></TD>
            <TD><INPUT TYPE="text" name="CITY<%=myRs.Fields("SAID") %>" value = "<%=myRs.Fields("CITY")%>" style="background:white;color:BLACK;font-family:arial, verdana; font-size:15px; height:25px;font-color:#ffff00;"
                                size="20"></B></TD>
            <TD><INPUT TYPE="text" name="COUNTRY<%=myRs.Fields("SAID") %>" value ="<%=myRs.Fields("COUNTRY")%>" style="background:white;color:BLACK;font-family:arial, verdana; height:25px;font-size:15px; font-color:#ffff00;"
                                size="20"></TD>
            <TD><INPUT TYPE="checkbox" name="check" value ="<%=myRs.Fields("SAID")%>" style="background:white;color:BLACK;font-family:arial, verdana; font-size:10px; font-color:#ffff00;"
                                size="5"></TD></TR>
            <%
        myRs.MoveNext

       wend
        %>
        <TR><TD COLSPAN=3><INPUT TYPE="submit" name="btnval" value="Uppdatera" style="font-family:arial, verdana; font-size:13px; font-color:black;width=70px;color=BLACK;height:25px;background-color: #D3D3D3">
        <INPUT TYPE="submit" name="btnval" value="Ta bort rad" style="font-family:arial, verdana; font-size:13px; font-color:black;width=70px;color=BLACK;height:25px;background-color: #D3D3D3"></TD></TR></Form></Table>
        <%

        Set myRs = Nothing
        Set myConn = Nothing







Similar Threads
Thread Thread Starter Forum Replies Last Post
Update Query Help dalezjc Classic ASP Basics 8 March 18th, 2008 08:49 AM
I solved insert query.now see this Update Query. [email protected] VB.NET 2002/2003 Basics 2 September 21st, 2006 12:48 AM
Update query trab Access 1 May 11th, 2006 03:58 PM
Please Help me about UPDATE query huyremy VB Databases Basics 8 September 29th, 2004 03:45 AM
Update query edcaru Access 3 June 14th, 2004 03:04 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.