如何在没有数据绑定的情况下使用SQL阅读器填充组合框 [英] How do I use SQL reader to fill a combobox without a databind

查看:96
本文介绍了如何在没有数据绑定的情况下使用SQL阅读器填充组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用SQLreader来填充组合框,我在youtube上观看了一个视频,而且一个人有一个我认为对我也有用的解决方案。当我尝试在我的sqldatareader之后提供的2行代码时,我得到了一个'从字符串转换营业执照号码输入'整数'是无效的。'



这里是代码:

 Dim buslicense As String = dr.GetString(营业执照号码)。 
businesslicensecombobox.Items.Add(buslicense)





我尝试过:



试图将其切换为使用getint32而不是getstring,它给了我相同的错误信息。

解决方案

你可以删除 GetString 并使用下面的代码,它会按照你的预期



 Dim buslicense As String = dr(营业执照号码)。ToString 
businesslicensecombobox.Items.Add(buslicense)







如果你想要我们 GetString 然后在选择语句中检查列的索引并给出索引ID,如



 ' 如果你的select语句是来自yourtable的SELECT [营业执照号码 
Dim buslicense As String = dr.GetString( 0 )。ToString
businesslicensecombobox.Items.Add(buslicense)


I am trying to use an SQLreader to fill a combobox, I watched a video on youtube and a guy had a solution that I thought would work for me also. when I tried the 2 lines of code he provided after my sqldatareader I got an "'Conversion from string "business license number" to type 'Integer' is not valid.'"

here is the code:

Dim buslicense As String = dr.GetString("business license number").
         businesslicensecombobox.Items.Add(buslicense)



What I have tried:

tried to switch it to use getint32 instead of the getstring and it gave me the same error message.

解决方案

You can remove the "GetString" and use the below code, it will as you expected

Dim buslicense As String = dr("business license number").ToString
businesslicensecombobox.Items.Add(buslicense)




And if you want to us "GetString" then in the select statement check the index for the column and give the index id like

'if your select statement is "SELECT [business license number] from yourtable"
Dim buslicense As String = dr.GetString(0).ToString
businesslicensecombobox.Items.Add(buslicense)


这篇关于如何在没有数据绑定的情况下使用SQL阅读器填充组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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