티스토리 뷰

c# 윈폼 콤보박스에 mysql 내용 open하지 않고 불러오기 


string query = "select * from customer_tab";

MySqlCommand cmd;


cmd = new MySqlCommand(query, conn);


MySqlDataAdapter da = new MySqlDataAdapter(cmd);

DataTable table = new DataTable("myTable");

da.Fill(table);


foreach (DataRow row in table.Rows)

{

     for (int i = 0; i < row.ItemArray.Length; i++)

     {

          comboBox1.Items.Add(row.ItemArray[1].ToString());


     }

}



내가 적용한 코드

     MySqlConnection myConn = new MySqlConnection("datasource = '" + this.textBox_host_ip.Text +"';port=3306;username=root;password=password");

            string selectstring = "select * from wdata_mdb.layout_db";

            MySqlDataAdapter myadp = new MySqlDataAdapter(selectstring, myConn);

            DataTable table = new DataTable("str_layout");


            myadp.Fill(table);

       

            foreach (DataRow row in table.Rows)

            {

                    this.cb_layout.Items.Add(row.ItemArray[1].ToString());

            }


// ItemArray[db에 저장되어 있는 순서, 갖고오고 싶은것이 몇번째인지 알고 가져오면됨]

댓글
최근에 달린 댓글
글 보관함
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Total
Today
Yesterday
    뽀로로친구에디
    최근에 올라온 글