我正在为数据库编写一个只读前端,似乎找不到找到使数据保持同步的方法。 我可以查询数据库并将结果放入DataTable中,然后将其附加到DataSet并将其用作DataGridView的DataSource,我正在苦苦挣扎的是刷新DataTable / DataSet中的行,并且更改反映在DataGridView。
DataTable orders = new DataTable();
DataTable lines = new DataTable();
DataSet dataSet = new DataSet();
private string orderQuery = "SELECT oh_ord_no AS OrderID, oh_stat AS OrderStatus, oh_cu_no AS CustomerID, cus_name AS CustomerName, cus_price_no AS PriceBand, cus_ac_manager AS AccountManager, oh_ord_type AS OrderType, oh_ord_ref AS OrderReference, oh_del_meth AS DeliveryMethod, oh_op_no AS InputBy, oh_route_no AS Route, CAST(SQL_DATE,DATEADD(day,-1,oh_ord_date)) AS OrderDate, CAST(SQL_DATE,DATEADD(day,-1,oh_del_date)) AS DeliveryDate, oh_head_text AS HeaderText, oh_foot_text AS FooterText, oh_total_units AS TotalUnits, oh_ord_value AS OrderValue, CAST(SQL_DATE,DATEADD(day,oh_status_change_date,'1899-12-31')) AS StatusChangeDate, oh_status_change_time AS StatusChangeTime, oh_conf_no FROM admin.sffoh1 LEFT JOIN admin.sdfcus ON oh_cu_no = cus_no";
private string orderLines = "SELECT ilf_ord_no AS OrderID, ilf_prod_ptr AS ProductID FROM admin.sffilf";
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
orders = SwordsData.GetData(orderQuery, "orders");
orders.AcceptChanges();
lines = SwordsData.GetData(orderLines, "lines");
dataSet.Tables.Add(orders);
dataSet.Tables.Add(lines);
dataview.DataSource = dataSet;
dataview.DataMember = "orders";
}
private void timer1_Tick(object sender, EventArgs e)
{
orders.Reset();
orders = SwordsData.GetData(orderQuery, "orders");
lines = SwordsData.GetData(orderLines, "lines");
dataSet.GetChanges();
}
那是我到目前为止所拥有的。我似乎无法在网上找到任何可以帮助我的东西:(
任何帮助或建议将不胜感激。 李