Error Converting Data Type Varchar To Float C#
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies error converting data type varchar to float sql server of this site About Us Learn more about Stack Overflow the company Business error converting data type varchar to float sql server 2008 r2 Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Converting data type varchar to float up vote 0 down vote favorite I just need to update some cells in my database by calculating some figures. But i dont know why there is an exception still popin up: Converting data type varchar to float. Any thoughts what could be wrong ? im watching on this for like 2 hours ... Item oldItem = new Item(); Item newItem = new Item(); oldItem = cmbItems.SelectedItem as Item; newItem.PredaneMnozstvo = oldItem.PredaneMnozstvo + 1; newItem.Mnozstvo = oldItem.Mnozstvo - 1; if(!String.IsNullOrEmpty(txtAkcia.Text)) newItem.HrubyZisk = oldItem.PredajnaCena - oldItem.NakupnaCena - double.Parse(txtAkcia.Text); else newItem.HrubyZisk = oldItem.PredajnaCena - oldItem.NakupnaCena; newItem.CistyZisk = Math.Round(newItem.HrubyZisk * 0.81,2); broker.UpdatePredal(newItem, oldItem); public void UpdatePredal(Item newItem, Item oldItem) { try { string sql = "UPDATE Sklad SET Mnozstvo= '"+newItem.Mnozstvo+"', PredaneMnozstvo= '"+newItem.PredaneMnozstvo+"',HrubyZisk= '"+newItem.HrubyZisk.ToString()+"', CistyZisk='"+newItem.CistyZisk+"' WHERE ID=" + oldItem.Id; cmd = new SqlCommand(sql, connection); connection.Open(); cmd.ExecuteNonQuery(); } catch (Exception eX) { MessageBox.Show(eX.Message); } } any suggestions? c# sql wpf share|improve this question edited Mar 9 '14 at 13:45 asked Mar 9 '14 at 13:17 franzp 59111 Which line throws exception? Also you shouldn't concatenate SQL command and use parameters instead –dkozl Mar 9 '14 at 13:25 1 Please show the full exception, we're not psychic. –MatBailie Mar 9 '14 at 13:25 after ExecutingnonQuery and i dunno why cuz my types are all good no need to convert anything ... –franzp Mar 9 '14 at 13:28 add a comment| 1 Answer 1 active oldest votes up vote 2 down vote accept
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. http://stackoverflow.com/questions/22282679/converting-data-type-varchar-to-float Join them; it only takes a minute: Sign up Error converting data type varchar to float. Prepare statement up vote 1 down vote favorite I have been searching for a solution to this and so far found nothing that works despite some others having similar issues. I am running an SQL statement using the following code (sorry about http://stackoverflow.com/questions/10928084/error-converting-data-type-varchar-to-float-prepare-statement the hideous formatting. That is what we use here): ///
Tips/Tricks Top Articles Beginner Articles Technical Blogs Posting/Update Guidelines Article Help Forum Article Competition Submit an article or tip Post your Blog quick answersQ&A Ask a Question View Unanswered Questions View All Questions... http://www.codeproject.com/Questions/286369/how-to-convert-varchar-to-float C# questions Linux questions ASP.NET questions SQL questions VB.NET questions discussionsforums All Message http://p2p.wrox.com/sql-server-asp/12289-error-converting-data-type-varchar-float.html Boards... Application Lifecycle> Running a Business Sales / Marketing Collaboration / Beta Testing Work Issues Design and Architecture ASP.NET JavaScript C / C++ / MFC> ATL / WTL / STL Managed C++/CLI C# Free Tools Objective-C and Swift Database Hardware & Devices> System Admin Hosting and Servers Java .NET Framework Android iOS Mobile SharePoint error converting Silverlight / WPF Visual Basic Web Development Site Bugs / Suggestions Spam and Abuse Watch features Competitions News The Insider Newsletter The Daily Build Newsletter Newsletter archive Surveys Product Showcase Research Library CodeProject Stuff communitylounge Who's Who Most Valuable Professionals The Lounge  The Insider News The Weird & The Wonderful The Soapbox Press Releases Non-English Language > General Indian Topics General Chinese Topics help What is error converting data 'CodeProject'? General FAQ Ask a Question Bugs and Suggestions Article Help Forum Site Map Advertise with us About our Advertising Employment Opportunities About Us Ask a Question All Questions All Unanswered FAQ how to convert varchar to float. Rate this: Please Sign up or sign in to vote. See more: C# ASP.NET here with attched my coding it shows following error can anyone correct the error. Error: Error converting data type varchar to float. Error Codding: price_range = BulletedList3.Items[e.Index].Value; if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand cmd = new SqlCommand("select pro_img,pro_name,price from product where price= '" + price_range + "'and status='A' and type='retail' ", con); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); DataList1.DataSource = ds; DataList1.DataBind(); con.Close(); Posted 18-Nov-11 18:49pm M.Narmatha606 Updated 18-Nov-11 18:56pm v2 Add a Solution Comments srinivas vadepally 19-Nov-11 4:04am Narmatha, Datatypes of attribute from front end and back end(Database) should be equal. You are inserting price in textbox, treated as string. So the exception has come. 2 solutions Top Rated Most Recent Rate this: Please Sign up or sign in to vote. Solution 2 Accept Solution Reject Solution if your price column is float in Database use it
Unanswered Topics Wrox Programmer Forums > SQL Server > SQL Server ASP Error converting data type varchar to float. User Name Remember Me? Password Reminder Password Register Register | FAQ | Members List | Calendar | Today's Posts | Search SQL Server ASP Discussions about ASP programming with Microsoft's SQL Server. For more ASP forums, see the ASP forum category. Search Forums Show Threads Show Posts Advanced Search Find All Thanked Posts Go to Page... Welcome to the p2p.wrox.com Forums. You are currently viewing the SQL Server ASP 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 . Thread Tools Display Modes #1 (permalink) April 26th, 2004, 10:58 AM Trojan_uk Authorized User Join Date: Nov 2003 Location: , , . Posts: 19 Thanks: 0 Thanked 0 Times in 0 Posts Error converting data type varchar to float. Hi, I am receiving this error when trying to pass a value from ASP to SQL, below is the SP and a snippet from the update code from the ASP page, any ideas on how to rectifiy this. I have used a similar syntax in an add SP and that works fine, the supp_rent_val2 and usr_rent_val2 are the two values im passing in: ======SP======== CREATE PROCEDURE dbo.cnms_rentals_update @RENT_TYPE_SUPP FLOAT= NULL, @RENTAL_SUPP VARCHAR(1)=NULL, @RENT_TYPE VARCHAR(1)= NULL, @RENTAL FLOAT= NULL, @START_DATE DATETIME= NULL, @END_DATE DATETIME = NULL, @ROW_ID INT= NULL AS BEGIN UPDATE RENTAL SET RENT_TYPE_SUPP = convert(float,@RENT_TYPE_SUPP), RENTAL_SUPP = @RENTAL_SUPP, RENT_TYPE = @RENT_TYPE, RENTAL = convert(float,@RENTAL), START_DATE= @START_DATE, END_DATE = @END_DATE WHERE row_id = @ROW_ID END GO ==========ASP========= szSQL="EXEC dbo.cnms_rentals_update" if request("supp_rent_val2")<> "" then szSQL = szSQL & ", @RENT_TYPE_SUPP = " & request("supp_rent_val2") end if if request("supp_rent_per2")<> "" then szSQL = szSQL & ", @RENTAL_SUPP = '" & request("supp_rent_per2")& "'" end if