C# VS2015一个ComboBOX(下拉框)绑定数据库(SQL)某一列



C# VS2015一个ComboBOX(下拉框)绑定数据库(SQL)某一列_第1张图片using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 一个ComboBOX(下拉框)绑定数据库(SQL)某一列
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection("server=WINDOWS-CBBU2E6;database=OrderManagementSystem;Uid = sa; Pwd = 123");
            SqlDataAdapter da = new SqlDataAdapter("select  ZiDuan from dbo.AdvancedQueryDropDownList", con);
            DataSet ds = new DataSet();
            da.Fill(ds, "dbo.AdvancedQueryDropDownList");
            DataTable dtGroup = ds.Tables["dbo.AdvancedQueryDropDownList"];

            comboBox1.DataSource = dtGroup;
            comboBox1.DisplayMember = "ZiDuan";
            comboBox1.ValueMember = "ZiDuan";
        }
    }
}

你可能感兴趣的:(C# VS2015一个ComboBOX(下拉框)绑定数据库(SQL)某一列)