Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to pull data from a bunch of text boxes and then insert them into a database and all is well except for two, one is that if they are null they error but that's not the concern right now.

When I have a textbox that is supposed to take a number it says it cannot convert varchar to float. The inserts work if I do them directly in SQL Server though (using SQL Server 2008) so I know that it's something in the code.

My textbox is just a simple:

<asp:TextBox id="CID" runat="server"></asp:TextBox>
And the code I have for pulling the information from the textbox is:
float custID = float.Parse(CID.Text);

why ?




Sign
Lowongan Kerja
Posted
Updated 23-Oct-15 15:21pm
v2
Comments
phil.o 24-Oct-15 3:12am    
Could you show the way you construct your sql query?

1 solution

The error is a sql error. C# does not call strings varchar. So, you need to look at sql to see what is going wrong.

Perhaps you are passing in a blank for a float. That will not work. You can pass in DBNull.Value to pass in a null value.

If you debug your code you'll see which one is not passing in a correct value type.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900