[英]How I Can Show More Table In Datagridview C#
我可以使用c#和mysql按日期排序在一個datagridview中顯示兩個表或多個表嗎?
我使用了此代碼,但沒有數據出現
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 。 萬一仍然無法正常工作,請嘗試.Refresh()
dataGridView1.DataSource = jedataset;
dataGridView1.Refresh();
編輯:如果您仍然看不到數據添加:
dataGridView1.AutoGenerateColumns = true
(我不知道您是否已經添加了列)
編輯2: 在這里找到此代碼,但我沒有對其進行測試,但是您可以對其進行修改,然后嘗試嘗試:
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");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.