繁体   English   中英

如何在Datagridview C#中显示更多表

[英]How I Can Show More Table In Datagridview C#

我可以使用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;
      }

谢谢

据我所知, 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM