输入的字符串格式不正确.无法存储...预期类型为Int32. [英] Input string was not in a correct format.Couldn't store ..... Expected type is Int32.

查看:80
本文介绍了输入的字符串格式不正确.无法存储...预期类型为Int32.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道问题出在哪里,但不知道如何解决.

在数据库中给我错误的列是tipe"NUMBER"并接受空值.

但是当执行查询时....

I know where is the problem, but do not know how to fix it.

Column that gives me the error in the database is tipe "NUMBER" and accept null values​​.

But when execute query ....

Program.Connection.CommandText = "select Contracts.ContractId, Contracts.StartDate, Contracts.EndDate, Contracts.Procent, ContractItems.DeletedId AS ContracteActive, sum (ContractItems.Payment) AS Total_Platit, Now () AS DataCurenta from Contracts INNER JOIN ON ContractItems Contracts.ContractId = ContractItems.ContractId WHERE ClientID = @ ClientID "
                 + "GROUP BY Contracts.ContractId, Contracts.StartDate, Contracts.EndDate, Contracts.Procent, ContractItems.DeletedId ORDER BY Contracts.EndDate AND (((ContractItems.DeletedId) Is Null)), Contracts.EndDate DESC";
             Program.Connection.AddParameter ("@ ClientID", ClientID.Text);


查询,当它找到具有空字段的记录时,它给了我这个错误,即如何读取数据(无论该字段为空还是包含数字).?


the query when it finds a record that has null field, it gives me this error, how to read data whether that field is null or contain a number.?

推荐答案

您是否需要DeleteId为null的那些数据?如果没有,您可以添加
这样的WHERE语句
Do you need those data where DeleteId is null? If not, you could add a WHERE statement like
WHERE ContractItems.DeletedId is not null

.
但是我有一些疑问... ClientId还是数字-文本框ClientId包含其他字符吗?
您可以将其替换为

before the Group By clause.
But I have some doubts... Is ClientId also a number - and the TextBox ClientId contains other characters?
You could replace the line with e.g.

Program.Connection.AddParameter ("@ClientID", Convert.ToInt32(ClientID.Text));


最好使用ISNULL函数进行检查.
ISNULL(参数,0).在这种情况下,如果参数为null,则结果为0,否则将重新选择该值.
it''s better u check with ISNULL function.
ISNULL(parameter, 0). in this if the parameter is null then the result is 0 else the value will be refelected.


您应在代码之前检查TextBox.Text.
TextBox.Text必须可转换为Int32.如果它包含任何字母,您将会遇到此错误.
You should check TextBox.Text before your code.
The TextBox.Text must convertable to Int32. If it contains any letter you would expect this error.


这篇关于输入的字符串格式不正确.无法存储...预期类型为Int32.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆