-2

我在 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;
    }

}
4

1 回答 1

1

您可以使用 sqldependency 在更新行时更新您,而不是一遍又一遍地访问数据库。

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

或者

如果你熟练,你可以去 Asynchronous Page 或SignalR

或者

AJAX 回调

于 2013-07-11T08:23:29.357 回答