Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics 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 January 18th, 2008, 11:55 AM
Authorized User
 
Join Date: Jul 2006
Posts: 22
Thanks: 1
Thanked 0 Times in 0 Posts
Default Syntax error converting the varchar value...

When I enter any non-integer value into the txtPriceQuoted text box, I get the error "Syntax error converting the varchar value '1.25' to a column of data type int". Within the database, the PriceQuoted field is varchar(50) and defined as such in the stored procedure. I am not trying to convert that value anywhere, so why the error?


        protected void lnkSave_Click(object sender, System.EventArgs e)
        {

            string connString = ConfigurationManager.ConnectionStrings["crConnString"].ConnectionString;
            SqlConnection cn = new SqlConnection(connString);
            SqlCommand cmdUpd = new SqlCommand("Save_sp", cn);
            cmdUpd.CommandType = CommandType.StoredProcedure;

            if (rdbVirtualNo.Checked)
            {
                cmdUpd.Parameters.Add(new SqlParameter("@PricingQuotedFlag", false));
                cmdUpd.Parameters.Add(new SqlParameter("@PriceQuoted", ""));
                cmdUpd.Parameters.Add(new SqlParameter("@PriceApprover", ""));
            }
            else
            {
                cmdUpd.Parameters.Add(new SqlParameter("@PricingQuotedFlag", true));
                cmdUpd.Parameters.Add(new SqlParameter("@PriceQuoted", txtPriceQuoted.Text));
                cmdUpd.Parameters.Add(new SqlParameter("@PriceApprover", txtApproverName.Text));
            }

            cmdUpd.Connection.Open();
            cmdUpd.ExecuteNonQuery();
            cmdUpd.Connection.Close();
            Response.Redirect("DetCr.aspx?CrID=" + Request.QueryString["CrID"]);
        }


 
Old January 18th, 2008, 04:26 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Can you post the stored procedure? I suspect that you are trying to compare the @PriceQuoted procedure argument to a table column that IS of type INT. You'll need to convert at some point.

-Peter
 
Old January 21st, 2008, 10:27 AM
Authorized User
 
Join Date: Jul 2006
Posts: 22
Thanks: 1
Thanked 0 Times in 0 Posts
Default

CREATE PROC dbo.Save_sp

@CrID int,
@PricingQuotedFlag bit,
@PriceQuoted varchar(50),
@PriceApprover varchar(100)

IF EXISTS(SELECT CrID FROM Cr WHERE CrID = @CrID)
BEGIN
        UPDATE Cr SET PricingQuotedFlag = @PricingQuotedFlag, PriceQuoted = @PriceQuoted, PriceApprover = @PriceApprover

        WHERE CrID = @CrID
END
GO

 
Old January 22nd, 2008, 05:35 AM
Authorized User
 
Join Date: Sep 2007
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What type is the Cr.PriceQuoted field? Varchar(50)?

And you could try to use

cmdUpd.Parameters.AddWithValue("PriceQuoted", txtPriceQuoted.Text);

instead of Parameters.Add(new SqlParameter ... ) thingy.

 
Old January 23rd, 2008, 01:17 PM
Authorized User
 
Join Date: Jul 2006
Posts: 22
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Yes, Cr.PriceQuoted is varchar(50)

addwithvalue gives the same error

 
Old January 23rd, 2008, 10:25 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

This line is jumping out at me:

   IF EXISTS(SELECT CrID FROM Cr WHERE CrID = @CrID)

Where are you adding the @CrID parameter to the command object? I don't see it in your posted code. How are you adding it if you are? It's possible that this is the problem. One of the values in this part (CrID = @CrID) of the above line is an integer and the other is not. The database engine can not implicitly convert an INT into a character/string value.

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
Syntax error converting datetime from character st vinod_yadav1919 SQL Server 2000 2 September 10th, 2010 10:11 AM
Error converting data type varchar to int. - SQL baysaa SQL Server ASP 1 March 16th, 2008 11:56 PM
Syntax error converting datetime from character st kkrish SQL Server 2000 11 September 6th, 2006 06:46 AM
Syntax error converting datetime from character st Uppa SQL Server 2000 2 February 8th, 2005 08:01 PM
Error converting data type varchar to float. Trojan_uk SQL Server ASP 5 April 27th, 2004 02:56 AM





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