数据库断开式

Posted 水泽

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数据库断开式相关的知识,希望对你有一定的参考价值。

//建立与数据库的连接
            string strcon = ConfigurationManager.ConnectionStrings["XU"].ConnectionString;
            SqlConnection con = new SqlConnection(strcon);
           // 指定数据集
            SqlCommand com = new SqlCommand();
            com.CommandText = "select * from dbstudents ";
            com.Connection = con;
            //建表
            DataTable dt = new DataTable();

            //适配器
            SqlDataAdapter sda = new SqlDataAdapter();

            sda.SelectCommand = com;
            //充满table
           sda.Fill(dt);

            //foreach (DataRow row  in dt.Rows)
            //{
            //   comboBox2.Items.Add(row[0].ToString());

            //}
            comboBox2.DataSource = dt;
            comboBox2.DisplayMember = "name";
            comboBox2.ValueMember = "age";

 

以上是关于数据库断开式的主要内容,如果未能解决你的问题,请参考以下文章