C#中怎么将mysql中的数据库的表显示在form窗体中? 以下是我写的代码,运行没有错,但是没有显示. 10
{
DataSet dsSource = new DataSet(); //这是源数据库记录集,先获取源数据库所有数据在此记录集
string Conn = "Data Source='localhost';Database='lunwen2';User Id='root';Password='123456'";
MySqlConnection mycn = new MySqlConnection(Conn);
mycn.Open();
string sql = "select *from paper_textclassification2";// paper_textclassification2为表名
MySqlCommand cmd = new MySqlCommand(sql, mycn);
cmd.Connection = mycn;
MySqlDataAdapter Da = new MySqlDataAdapter(sql, mycn);
Da.Fill(dsSource," paper_textclassification2");
DataGridView GridView1 = new DataGridView();
GridView1.DataSource = dsSource.Tables["paper_textclassification2"];
}
是不是还需要绑定,绑定的话用什么函数?我用的是visual 2013 展开
{
DataSet dsSource = new DataSet(); //这是源数据库记录集,先获取源数据库所有数据在此记录集
DataTable dtSource = new DataTable(); //DataSet是DataTable的集合
string Conn = "Data Source='localhost';Database='lunwen2';User Id='root';Password='123456'";
MySqlConnection mycn = new MySqlConnection(Conn);
mycn.Open();
string sql = "select *from paper_textclassification2";// paper_textclassification2为表名
MySqlCommand cmd = new MySqlCommand(sql, mycn);
cmd.Connection = mycn; //这句可以不用写,没有任何意义
MySqlDataAdapter Da = new MySqlDataAdapter(sql, mycn);
Da.Fill(dsSource);
dtSource = dsSource.Tables[0];
DataGridView GridView1 = new DataGridView();
GridView1.DataSource = dtSource;
}
感谢你的回答,,,,但是,还是不行,没有显示出来,和我之前的代码运行后的反应一样
public List<Department> getAllDepartmentInfo()
{
List<Department> iDepartmentSet = new List<Department>();
string strSQL = "select * from department";
iOracleCommand = new OracleCommand(strSQL, con);
try {
con.Open();
iDatabaseReader = iOracleCommand.ExecuteReader();
DataSet ds = new DataSet();
OracleDataAdapter oda = new OracleDataAdapter(iOracleCommand);
oda.Fill(ds);
DataTable dt = ds.Tables[0];
for (int i = 0; i < dt.Rows.Count; i++){
//处理语句
iDepartmentSet.Add(it);
}
}
catch (Exception ex){
MessageBox.Show(ex.Message);
}
con.Close();
return iDepartmentSet;
}
this.lv_department.ItemsSource = iOracleOperator.getAllDepartmentInfo(); //设置数据源