After linking my VB project to the database, I want to fill a combobox with values from a certain table. The problem is that instead of loading combobox1 and combobox2 with city and state, it loads city_code and state_code. 1 I have two tables in a SQL Server database. ("Text", BindingSource1, "myname")Ĭ("Text", BindingSource1, "city_code")Ĭ("Text", BindingSource1, "state_code")Ĭmd = New OleDbCommand("select * from mycity", conn)Ĭmd = New OleDbCommand("select * from mystate", conn) ![]() ![]() Imports SqlSamples.Classes Public Class Form1 Private Sub InsertButtonClick (sender As Object, e As EventArgs) Handles InsertButton.Click If CompanyNameComoboBox.SelectedIndex > -1 Then Dim primaryKey. Also we can populate a combo box from a dataset values. ComboBox name is CompanyNameComoboBox, the Import statement points to the class to perform data operations in a folder named Classes. This is economical because there is nothing new created for the CBO: ComboBox.DataSource fooDataTable ComboBox.DisplayMember 'column name in DT' Another way is to modify your loop: (row('col name'). The VB.Net SqlDataAdapter object allows us to populate Data Tables in a DataSet. Do the following query to create a table in the database that you have created. This is my code Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.LoadĬonn = New OleDbConnection("Provider=.12.0 Data Source=c:\users\desraj\desktop\mydb.accdb ")Īdap = New OleDbDataAdapter("select * from mytable", conn)īindingNavigator1.BindingSource = BindingSource1 The best solution is what LarsTech suggested and use the existing datatable as the datasource. After that, right click the database, then select New Database and name it dbperson 3. When you select the ComboBox which you inserted, you can click on Properties under the Developer tab: Image 2. I have this form where i am binding data with the controls. In order to insert a ComboBox in the Worksheet, you need to go to the Developer tab, click Insert and under ActiveX Controls choose Combo Box: Image 1.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |