2013-07-11 24 views
-1

在ASP.Net中設計物流網站時,客戶可以下訂單,訂單將插入到數據庫中。 我想,當新訂單插入數據庫時​​,它會自動向員工發送新訂單的通知。 現在的問題是,當數據庫更改時,如何操作以下代碼以獲取實時通知?如何使用MSSQL在ASP.Net中獲取實時數據庫更改通知

public class FreightOrderList 
{ 

    int customerID = 0; 

    public int CustomerID 
    { 
     get { return customerID; } 
     set { customerID = value; } 
    } 
    string email = string.Empty; 



    public FreightOrderList() 
    { 
     //default Cons 
    } 

    public FreightOrderList(int _customerID) 
    { 
     this.customerID = _customerID; 

    } 

    public DataSet displayOrders() 
    { 
     string ConString = ConfigurationManager.ConnectionStrings["LGDB"].ToString(); 
     SqlConnection sqlConnectionObj = new SqlConnection(ConString); 
     SqlDataAdapter sqlDataAdapterObj = new SqlDataAdapter(); 
     DataSet dataSetObj = new DataSet(); 
     sqlDataAdapterObj.SelectCommand = new SqlCommand(); 
     sqlDataAdapterObj.SelectCommand.Connection = sqlConnectionObj; 
     sqlDataAdapterObj.SelectCommand.CommandText = "customerShipOrderProc"; 
     sqlDataAdapterObj.SelectCommand.CommandType = CommandType.StoredProcedure; 
     sqlConnectionObj.Open(); 
     sqlDataAdapterObj.SelectCommand.Parameters.AddWithValue("customerID", this.CustomerID); 

     sqlDataAdapterObj.Fill(dataSetObj,"customerShipOrder"); 
     sqlConnectionObj.Close(); 
     return dataSetObj; 
    } 

} 
+0

那是一個不錯的主意,但什麼是你的題? – Jamiec

+0

我的問題是我應該寫什麼代碼? – Iatrochemist

+0

請讓你的問題更清楚。如果我是對的,那麼在網頁上需要一些Facebook類型的通知,當某些更新到達您的帳戶時。 –

回答

1

您可以使用sqldependency,它在更新行時更新您,而不是一次又一次地敲擊數據庫。

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldependency.aspx

如果你是熟練的,你可以去異步頁或SignalR

AJAX回調

+0

謝謝Amit,可以用ajax來完成嗎? – Iatrochemist

+1

@Alizerax,當然是。見http://www.clientsideasp.net/2009/03/01/aspnet-ajax-poll-using-jquery-a-complete-implementation-with-admin-part/ –

相關問題