我可以使用 C# 和 mysql 按日期排序在一个 datagridview 中显示两个或多个表吗?
例如:
<小时/>|表1.销售编号|表1.salesMoney |表1.日期1 |
|表2.购买否|表2.purchMoney |表2.日期2 |
|表2.购买否|表2.purchMoney |表2.日期3 |
|表1.销售编号|表1.salesMoney |表1.日期4 |
|表1.销售编号|表1.salesMoney |表1.日期5 |
<小时/>我使用了此代码,但没有出现数据
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;
}
谢谢
最佳答案
据我所知,DataBind() 仅适用于 Web 表单。尝试仅与属性 .DataSource 绑定(bind)。万一仍然不起作用,请尝试 .Refresh()
dataGridView1.DataSource = jedataset;
dataGridView1.Refresh();
编辑:如果您仍然没有看到任何数据,请添加:
dataGridView1.AutoGenerateColumns = true
(我不知道您是否已经添加了这些列)
编辑2:找到此代码here ,我没有测试它,但你可以调整它并尝试是否有效:
private static void DemonstrateMergeTable()
{
DataTable table1 = new DataTable("Items");
// Add columns
DataColumn column1 = new DataColumn("id", typeof(System.Int32));
DataColumn column2 = new DataColumn("item", typeof(System.Int32));
table1.Columns.Add(column1);
table1.Columns.Add(column2);
// Set the primary key column.
table1.PrimaryKey = new DataColumn[] { column1 };
// Add some rows.
DataRow row;
for (int i = 0; i <= 3; i++)
{
row = table1.NewRow();
row["id"] = i;
row["item"] = i;
table1.Rows.Add(row);
}
// Accept changes.
table1.AcceptChanges();
PrintValues(table1, "Original values");
// Create a second DataTable identical to the first.
DataTable table2 = table1.Clone();
// Add three rows. Note that the id column can't be the
// same as existing rows in the original table.
row = table2.NewRow();
row["id"] = 14;
row["item"] = 774;
table2.Rows.Add(row);
row = table2.NewRow();
row["id"] = 12;
row["item"] = 555;
table2.Rows.Add(row);
row = table2.NewRow();
row["id"] = 13;
row["item"] = 665;
table2.Rows.Add(row);
// Merge table2 into the table1.
Console.WriteLine("Merging");
table1.Merge(table2);
PrintValues(table1, "Merged With table1");
}
关于c# - 如何在 Datagridview C# 中显示更多表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34502537/