日期:2014-05-18 浏览次数:20839 次
//获取数据库数据并填充一个DataTable SqlConnection conn = new SqlConnection("连接数据库字符串"); SqlDataAdapter da = new SqlDataAdapter("SQL查询语句",conn); conn.Open(); DataTable dt = new DataTable(); da.Fill(dt); da.Dispose(); conn.Close(); conn.Dispose(); //把DataTable中的相关数据显示到界面中 this.textBox1.Text = dt.Rows["行"]["列"].ToString(); this.textBox2.Text = dt.Rows["行"]["列"].ToString(); this.textBox3.Text = dt.Rows["行"]["列"].ToString(); ..........................
------解决方案--------------------
string Afile = "provider=microsoft.jet.OLEDB.4.0;Data source=" + name.into.nto("ServerPath") + "";
OleDbConnection AconnStr = new OleDbConnection(Afile);
OleDbCommand scmd = new OleDbCommand("select top 200 * from client where 字段='" + gainame + "' and 字段='" + comboBox3.Text.Trim() + "' order by id", AconnStr);
OleDbDataReader odr = null;
AconnStr.Open();
odr = scmd.ExecuteReader();
if (odr != null)
{
while (odr.Read())
{
textBox7.Text = odr["字段"].ToString();
textBox10.Text = odr["字段"].ToString();
textBox16.Text = odr["字段"].ToString();
textBox11.Text = odr["字段"].ToString();
textBox12.Text = odr["字段"].ToString();
textBox13.Text = odr["字段"].ToString();
textBox14.Text = odr["字段"].ToString();
textBox15.Text = odr["字段"].ToString();
comboBox3.Text = odr["字段"].ToString();
}
odr.Close();
------解决方案--------------------