Click here to Skip to main content
15,901,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi friends how can i connect database one coluam data to my combobox by using codes in program
Posted

try something like this:-
Private Sub FillCombo()
        Try
            Dim fillcon As New OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=path to access file.mdb;")
            Dim asql As String = ("SELECT * FROM Items ORDER BY ItemName")
            Dim da As New OleDbDataAdapter(asql, fillcon)
            Dim ds As New DataSet
            da.Fill(ds)
            ItemNameCombo.ValueMember = "ItemName"
            ItemNameCombo.DataSource = ds.Tables(0)
            ItemNameCombo.SelectedIndex = 0
        Catch ex As Exception
            MsgBox("ERROR : " & ex.Message.ToString)
        End Try
    End Sub


refer:-
http://www.dreamincode.net/forums/topic/207090-using-code-to-bind-combo-box-to-access-database/[^]
 
Share this answer
 
private void Bind_Combo()
{
DataTable dt = new DataTable();
samplecontroller controller = new samplecontroller (); //Your Logic layer call from database(just calling)
dt = controller.sample_Select(entity); //Your datasource is input here
if (dt.Rows.Count > 0)
{
this.combobox.DataSource = dt;
this.combobox.DisplayMember = "sample_Name";
this.combobox.ValueMember = "sample_ID";
}
this.combobox.Text = "Please select";
}
 
Share this answer
 
 
Share this answer
 
private void _BindCombo()
       {

           try
           {
               string conString = "";
               OleDbConnection con = new OleDbConnection(conString);
               con.Open();
               string query = "";
               OleDbCommand cmd = new OleDbCommand(query, con);
               OleDbDataReader dr = cmd.ExecuteReader();
               DataTable dt = new DataTable();
               dt.Load(dr);
               if (dt.Rows.Count > 0)
               {
                   combobox.DataSource = dt;
                   combobox.DataTextField = "displayfield";
                   combobox.DataValueField = "valuefield";
                   combobox.DataBind();
               }
           }
           catch (Exception)
           {

               throw;
           }


       }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900