参数1无法从字符串转换为整数此消息显示 [英] Argument 1 Can Not Convert From Sting To Int This Message Show

查看:89
本文介绍了参数1无法从字符串转换为整数此消息显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个组合框链接到数据库.为此,我编写了一个程序,但是却显示了一个问题.我的错误代码在下面

I Want To Link A Combobox To Database . For This I Write A Proggrame But One Problem Show .My Error Code Bellow

推荐答案

您应该检查DbDataReader类(或正在使用的DbDataReader派生类的文档).通用类没有使用String作为参数的GetString方法.相反,仅采用应该为序数的Int 数字.

you should check the DbDataReader class (or the documentation of the class you are using that derives of DbDataReader). The common classes does not have a GetString method that takes a String as argument. Instead only a Int is taken which should be the ordinal number.

您可能会打这样的电话:

You could have a call like this:

字符串sname = reader.GetString(reader.GetOrdinal(" Name")));

string sname = reader.GetString(reader.GetOrdinal("Name"));

(您甚至可以考虑创建一个扩展DbDataReader的类以具有这些方法.这样,您只需编写一次即可.另一个缺失"的实现是处理DbNull.因此,该方法可以为空值(例如 int?)并检查DbNull也很有用.)

(You might even think about creating a class that extends the DbDataReader to have these methods. That way you only have to code it once. The other implementation that is "missing" is handling DbNull. So a method that gets nullable values (e.g. int?) and checks for DbNull is also useful.)

以诚挚的问候,

康拉德


这篇关于参数1无法从字符串转换为整数此消息显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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