locked
C# Combobox Using Oracle Database OLEDB connecion RRS feed

  • Question

  • Hello , i have  application using  some combobox and using oracle database, OLEDB driver , how can load  database table data in combobox ?
    Tuesday, July 11, 2017 7:51 PM

Answers

    • Proposed as answer by Stanly Fan Thursday, July 13, 2017 6:14 AM
    • Marked as answer by Mr.Khan for U Monday, January 8, 2018 1:06 PM
    Tuesday, July 11, 2017 7:58 PM
  • Hi

    Please refer to the folliwng demo:

            private void button1_Click(object sender, EventArgs e)
            {
                DataTable dt = new DataTable();
    
                string ConnectionString = "Data Source=dzjc_2005;user=kk;password=kk;";  
                OracleConnection conn = new OracleConnection(ConnectionString);  
    
                conn.Open();
                OracleCommand cmd = conn.CreateCommand();
                cmd.CommandText = "SELECT rname,did,rchannel FROM nwvideo.n_road ";  
                OracleDataReader dr = cmd.ExecuteReader();
                dr.Fill(dt);
    
                if (dr.HasRows)
                {
                    comboBox1.Items.Clear();//清空ComBox  
                    while (dr.Read())
                    {
                        comboBox1.DataSource = dt;
                        comboBox1.DisplayMember = dt.Columns[1].ColumnName;
                        comboBox1.ValueMember = dt.Columns[0].ColumnName;
                    }
                }
                conn.Close();
                conn.Dispose();
            }

    Best Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Stanly Fan Thursday, July 13, 2017 6:13 AM
    • Marked as answer by Mr.Khan for U Monday, January 8, 2018 1:05 PM
    Wednesday, July 12, 2017 7:15 AM

All replies

    • Proposed as answer by Stanly Fan Thursday, July 13, 2017 6:14 AM
    • Marked as answer by Mr.Khan for U Monday, January 8, 2018 1:06 PM
    Tuesday, July 11, 2017 7:58 PM
  • Hi

    Please refer to the folliwng demo:

            private void button1_Click(object sender, EventArgs e)
            {
                DataTable dt = new DataTable();
    
                string ConnectionString = "Data Source=dzjc_2005;user=kk;password=kk;";  
                OracleConnection conn = new OracleConnection(ConnectionString);  
    
                conn.Open();
                OracleCommand cmd = conn.CreateCommand();
                cmd.CommandText = "SELECT rname,did,rchannel FROM nwvideo.n_road ";  
                OracleDataReader dr = cmd.ExecuteReader();
                dr.Fill(dt);
    
                if (dr.HasRows)
                {
                    comboBox1.Items.Clear();//清空ComBox  
                    while (dr.Read())
                    {
                        comboBox1.DataSource = dt;
                        comboBox1.DisplayMember = dt.Columns[1].ColumnName;
                        comboBox1.ValueMember = dt.Columns[0].ColumnName;
                    }
                }
                conn.Close();
                conn.Dispose();
            }

    Best Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Stanly Fan Thursday, July 13, 2017 6:13 AM
    • Marked as answer by Mr.Khan for U Monday, January 8, 2018 1:05 PM
    Wednesday, July 12, 2017 7:15 AM
  • Hi,

    So have you solved this problem now?

    I think the above reply can provide you with a solution, have you tried it?

    If so, hope you can close this thread by marking the reply as answer as this will help others looking for the same or similar issues down the road.

    Best Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, July 21, 2017 5:58 AM
  • yes many thanks
    Monday, January 8, 2018 1:06 PM