数据库断开式
时间:2021-07-01 10:21:17
帮助过:23人阅读
建立与数据库的连接
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";
数据库断开式
标签:rom com 数据集 code dap data 建表 foreach command