【发布时间】:2015-12-28 23:57:03
【问题描述】:
我可以使用 c# 和 mysql 按日期排序在一个 datagridview 中显示两个或多个表吗?
例如:
| table1.salesNo | table1.salesMoney | table1.date1 |
| table2.purchNo | table2.purchMoney | table2.date2 |
| table2.purchNo | table2.purchMoney | table2.date3 |
| table1.salesNo | table1.salesMoney | table1.date4 |
| table1.salesNo | table1.salesMoney | table1.date5 |
我使用了这段代码,但没有数据出现
private MySqlDataAdapter salesinvoices, purchasesinvoices;
private DataSet jedataset;
private void button2_Click(object sender, EventArgs e)
{
const string SELECT_salesinvoices = "SELECT * FROM sales_invoices";
const string SELECT_purchasesinvoices = "SELECT * FROM purchase_invoices";
// Compose the connection string.
string connect_string = Publics.je_Coonn;
// Create a DataAdapter to load the Addresses table.
salesinvoices = new MySqlDataAdapter(SELECT_salesinvoices,
connect_string);
// Create a DataAdapter to load the Addresses table.
purchasesinvoices = new MySqlDataAdapter(SELECT_purchasesinvoices,
connect_string);
// Create and fill the DataSet.
jedataset = new DataSet("je_coronasalesdbDataSet");
salesinvoices.Fill(jedataset, "sales_invoices");
purchasesinvoices.Fill(jedataset, "purchase_invoices");
// Bind the DataGrid to the DataSet.
dataGridView1.DataSource = jedataset;
}
谢谢
【问题讨论】:
-
在设置
DataSource之后看起来你需要dataGridView1.DataBind();。 -
谢谢,我试过了,但出现此错误 System.Windows.Forms.DataGridView' 不包含'DataBind' 的定义,并且没有扩展方法'DataBind' 接受类型的第一个参数
-
DataBind()不接受任何参数。尝试完全按照我在上一条评论中输入的方式添加该行。 -
我做了那个 dataGridView1.DataBind();正是