Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法将数据从MySQL中的特定表获取到Vb.net组合框_Mysql_Vb.net - Fatal编程技术网

无法将数据从MySQL中的特定表获取到Vb.net组合框

无法将数据从MySQL中的特定表获取到Vb.net组合框,mysql,vb.net,Mysql,Vb.net,这里是我的问题,我有一个组合框,我想用MySql中加载的表中的数据填充它。我使用了以下代码: Dim strSQL As String = "SELECT containers FROM tbl_items_containers" Dim da As New MySqlDataAdapter(strSQL, SQLConnection) Dim cmd As New MySqlCommand Dim ds As New Dat

这里是我的问题,我有一个组合框,我想用MySql中加载的表中的数据填充它。我使用了以下代码:

 Dim strSQL As String = "SELECT containers FROM tbl_items_containers"
        Dim da As New MySqlDataAdapter(strSQL, SQLConnection)
        Dim cmd As New MySqlCommand
        Dim ds As New DataSet

        SQLConnection.ConnectionString = ServerString

        cmd.Connection = SQLConnection

        da.Fill(ds, "tbl_items_containers")
        With cb_container_type
            .DataSource = ds.Tables("tbl_items_containers")
            .DisplayMember = "containers"
            .ValueMember = "containers"
            .SelectedIndex = 0

        End With
每次运行时显示的错误是:

System.Windows.Forms.dll中发生类型为“System.ArgumentOutOfRangeException”的未处理异常

其他信息:“0”的InvalidArgument=值对于“SelectedIndex”无效


现在是这样,我尝试从同一数据库中的另一个表中获取数据,代码运行正常。我的组合框中填充了数据。我以为问题出在数据库里,但我真的迷路了。我不知道该怎么办。关于错误的原因有什么想法吗?提前感谢。

请尝试使用
.DataSource=ds.Tables(0)
代替。在调试器中运行它。设置属性后,
.DataSource
的值是多少?它包含什么?所以一个明显的问题是,如果不设置
SelectedIndex
,会发生什么?你在组合框里看到什么了吗?如果查询返回数据,则应该在组合框中看到内容。如果没有,则查询不会返回任何行,或者您的代码在其他地方出错。这是在这里发布之前应该进行的非常基本的故障排除。哦,忘了说这是我在调试器中运行它时显示的错误。我已经尝试删除该行,每当我这样做时组合框都不会填充。