C # winform ComboBox dynamic drop-down list, ComboBox dynamically binds data in the database

Source: Internet
Author: User
Tags oracleconnection
Code
1 Public   Void Insertcomshopid (ComboBox CB)
2 {
3 CB. Items. Clear (); // Clear combox
4 Sqlcommand cmd =   New Sqlcommand ( " Select name from shop " , DB. getcon ()); // Construct the connection string and open the database connection
5 Sqldatareader SDR = Cmd. executereader ();
6 While (SDR. Read ())
7 {
8CB. Items. Add (SDR [0]. Tostring ());//Read data cyclically
9} // End Block while
10
11 SDR. Close (); // Close a dataset
12 DB. getcolse (); // Close database connection
13 }
14

Or

Code
1 String Connectionstring =   " Data Source = dzjc_2005; user = KK; Password = KK; " ; // Write connection string
2 Oracleconnection Conn =   New Oracleconnection (connectionstring ); // Create a new connection
3
4 Conn. open ();
5 Oraclecommand cmd = Conn. createcommand ();
6 Cmd. commandtext =   " Select rname, did, rchannel from nwvideo. n_road " ; // Write SQL statements here
7 Oracledatareader Dr = Cmd. executereader (); // Create an oracledatereader object
8
9 If (Dr. hasrows)
10 {
11 Cmbchannelselect. Items. Clear (); // Clear combox
12 While (Dr. Read ())
13 {
14Cmbchannelselect. Items. Add (Dr [2]. Tostring ());//Cyclic read area data
15
16}
17 }
18
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.