Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 18th, 2008, 11:55 AM
Authorized User
 
Join Date: Jul 2006
Location: , , .
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"]);
        }


Reply With Quote
  #2 (permalink)  
Old January 18th, 2008, 04:26 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
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
Reply With Quote
  #3 (permalink)  
Old January 21st, 2008, 10:27 AM
Authorized User
 
Join Date: Jul 2006
Location: , , .
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

Reply With Quote
  #4 (permalink)  
Old January 22nd, 2008, 05:35 AM
Authorized User
 
Join Date: Sep 2007
Location: , , Finland.
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.

Reply With Quote
  #5 (permalink)  
Old January 23rd, 2008, 01:17 PM
Authorized User
 
Join Date: Jul 2006
Location: , , .
Posts: 22
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Yes, Cr.PriceQuoted is varchar(50)

addwithvalue gives the same error

Reply With Quote
  #6 (permalink)  
Old January 23rd, 2008, 10:25 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:55 PM.


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