我是新的C#,所以也許我沒有正確地記錄它。C#與sql查詢結果變量
在我的C#
表格中,我把order nr.
放入表格中。 然後在sql
中檢查。
需要執行這個查詢:
獲取
OrderID
從Order nr.
需要檢查,如果
Order ID
是=爲了打開如果訂單被打開,則需要以C#運行#
Messagebox.Show("Order opened, try again later")
- 如果沒有打開,負載數據從
order
SQL查詢:
Declare @OrderID uniqueidentifier
SET @OrderID = (SELECT m.ID FROM [Agenda].[dbo].[orders] m
WHERE m.OrderNumber= @sqlordernr)
if EXISTS (SELECT 1 FROM [Agenda].[dbo].[System_Opened_Orders]
WHERE [email protected])
BEGIN
// Tell its opened, need try again later
END
ELSE
BEGIN
// Order is not openend, can get custommer data
select ID, OrderNumber, CustommerName, CustommerCity
FROM [Agenda].[dbo].[orders] where OrderNumber = @sqlordernr
END
C#代碼:
SqlConnection conn = new SqlConnection("Data Source=localhost;Initial Catalog=Agenda;Persist Security Info=True;User ID=sa;Password=xxxxxxxx");
conn.Open();
SqlCommand command = new SqlCommand(/*sql query*/, conn);
command.Parameters.AddWithValue("@sqlordernr", odernr);
using (SqlDataReader reader = command.ExecuteReader())
{
if (reader.Read())
{
// if order is opened then Messagebox.Show
// if is not opened
// String OrderCustommerName = reader.GetString(3).TrimEnd();
// String OrderCustommerCity= reader.GetString(4).TrimEnd();
// lbOrderData.Text = OrderCustommerName + " " + OrderCustommerCity;
}
}
conn.Close();
答案是好的,但如果你願意,你可以嘗試SQL [輸出參數](http://www.aspsnippets.com /Articles/How-to-return-Output-parameter-from-Stored-Procedure-in-ASPNet-in-C-and-VBNet.aspx)。 –