前提・実現したいこと
VB2015でMySQLのデータをコンボボックスに入れたい
該当のソースコード
VB
1 ''' <summary> 2 ''' ライン名に値を設定する 3 ''' </summary> 4 ''' <param name="cmbDCSIdentifyName">値を設定するコンボボックスコントロール</param> 5 Private Sub setComboBox(ByVal cmbDCSIdentifyName As ComboBox) 6 Dim readData As Table = New Table() 7 Dim task As SelectLineTask = New SelectLineTask(-1) 8 Dim Table As Table = WrappingStatus() 9 Dim connector As MySQLConnector 10 11 Try 12 connector = New MySQLConnector("localhost", 3306, "xxxx", "xxxx", "INTEGRATED_INSPECTION") 13 Using con As New MySqlConnection(connector.CreateConnection()) 14 con.Open() 15 con.BeginTransaction() 16 17 ' SQL文構築 18 Dim selectSQL As String = OpenSelectSQL() 19 20 ' SQLに変数をセット 21 Using cmd As MySqlCommand = New MySqlCommand(selectSQL, con) 22 task.PrepareParameter(cmd) 23 task.SetParameter(cmd, Table.rows.Item(0)) 24 25 ' 実行 26 Dim adapter As New MySqlDataAdapter(cmd) 27 28 Dim ds As DataSet = New DataSet 29 adapter.Fill(ds) 30 31 32 ' 取得したデータの格納 33 readData.InsertAll(ds) 34 35 Dim i As Integer = 0 36 While (readData.rows.Count <= i) 37 cmbDCSIdentifyName.Items.Add(readData) 38 i += 1 39 End While 40 End Using 41 End Using 42 Catch ex As MySqlException 43 44 Catch ex As IndexOutOfRangeException 45 End Try 46 End Sub
DBの値は
A1
B1
C1
D1
と仮定してください
試したこと
上記のコードの直前で
VB
1MsgBox(readData.rows.Count)
を実行すると"4"となるのでDBに接続は出来ていると思われます。
補足情報(FW/ツールのバージョンなど)
VS2015
MySQL8.0
回答2件
あなたの回答
tips
プレビュー