在visual studio 2013中将varchar转换为float asp.net时出错 [英] Error converting varchar to float asp.net in visual studio 2013
问题描述
我正在尝试从一堆文本框中提取数据,然后将它们插入到数据库中,除了两个之外一切都很好,一个是如果它们为空则会出错,但现在不是问题了。 />
当我有一个应该取一个数字的文本框时,它说它无法将varchar转换为float。如果我直接在SQL Server中使用插件(使用SQL Server 2008),插入工作,所以我知道它是代码中的东西。
我的文本框只是一个简单的:
< asp:TextBox id =" CID" runat =" server">< / asp:TextBox>
我从文本框中提取信息的代码是:
float custID = float。解析(CID.Text);
为什么?
< br $>
签名
Lowongan Kerja
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
推荐答案
错误是sql错误。 C#不调用字符串varchar。所以,你需要查看sql以查看出现了什么问题。
也许你正在为一个浮动传递空白。那样不行。您可以传入DBNull.Value以传入空值。
如果您调试代码,您将看到哪一个没有传递正确的值类型。
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.
这篇关于在visual studio 2013中将varchar转换为float asp.net时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!