How to bind the names of all data tables in a database to ComboBox

Source: Internet
Author: User
C # Expert Group: 207364916 expect you to join privatevoidForm1_Load (objectsender, EventArgse) {declare a SQLconnection object SqlConnectionsqlnewSqlConnection (serverWINDOWS-UBBCFE0; databaseVCD; uidsa; pwd123); declare a SQLcommand object SqlComman

C # Expert Group: 207364916 expect you to join the private void Form1_Load (object sender, EventArgs e) {// declare a SQLconnection object SqlConnection SQL = new SqlConnection (server = WINDOWS-UBBCFE0; database = VCD; uid = sa; pwd = 123); // declare a SQLcommand object SqlComman

C # Expert Group: 207364916 we look forward to your participation

Private void Form1_Load (object sender, EventArgs e)
{

// Declare a SQLconnection object
SqlConnection SQL = new SqlConnection ("server = WINDOWS-UBBCFE0; database = VCD; uid = sa; pwd = 123 ");

// Declare a SQLcommand object
SqlCommand sqlcmd = new SqlCommand ("SELECT Name FROM SysObjects Where XType = 'U' order by Name", SQL );

// Declare an object with DataAdapter
SqlDataAdapter sda = new SqlDataAdapter ();

// Execute the query statement
Sda. SelectCommand = sqlcmd;

// Create a DataSet object
DataSet ds = new DataSet ();

// Call the Fill () method of the DataAdapter object to Fill the dataset
Sda. Fill (ds, "Name ");

// Bind the combobox Dataset
ComboBox1.DataSource = ds. Tables ["Name"];

// Select the members displayed in combobox and display the Name column in combobox
ComboBox1.DisplayMember = "Name ";
}

Result After execution

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.