friends i have this table
Code:
itemID quantity invoice No
1 20 156651
1 10 56151
1 5 33000
5 15 5465465
5 4 465465
5 8 4654654
6 7 454654
6 2 44558
6 5 44
and a have wpf forms
contain button and text box and combo box to select itemid
i want using sql code
to subtract quantity from quantity table by using a textbox on wpf forms
with condition
for example if i enter 25 in a text box on wpf form
for itemid1
the code will check itemid and subtract for example 20 from first itemid (1) and 5 from second itemid (1) and so on
i work on the above
and i create this code
but not work with me
the foreach
loop for one row only
not all row
can you please give me guide line to correct this code
Code:
private void btnOpenUnits_Copy_Click(object sender, RoutedEventArgs e)
{
dblQuantity = Convert.ToDouble(this.Quntity.Text);
dataConnection GetQuantity = new dataConnection();
DataTable table = GetQuantity.loadingdata("SELECT Top 5 StoreTransAction.ItemID, StoreTransAction.UnitID, StoreTransAction.quantity,StoreTransAction.StoresTransactionID, StoreTransAction.InvoiceNo FROM StoreTransAction Where StoreTransAction.TransID = 1 And StoreTransAction.ItemID =@ItemID And StoreTransAction.UnitID =@UnitID Order by StoreTransAction.quantity DESC ;", this.cboItemName.SelectedValue, this.cboUnits.SelectedValue); // Get the data table.
dataGridtry.ItemsSource = table.DefaultView;
foreach (DataRow row in table.Rows) // Loop over the rows.
{
if (dblQuantity <= 0)
{
return;
}
if (dblQuantity >= Convert.ToDouble(row.ItemArray[2].ToString()))
{
dataConnection UpdateQuantity = new dataConnection();
string[] para = { "@RowQantity", "@itemID", "@StoreId", "@UnitID", "@StoresTransactionID" };
object[] val = { dblQuantity, this.cboItemName.SelectedValue, this.cboStore.SelectedValue, this.cboUnits.SelectedValue
, Convert.ToDouble(row.ItemArray[3].ToString()) };
UpdateQuantity.EditRecord("Update StoreTransAction SET StoreTransAction.quantity =[StoreTransAction].[quantity]-@RowQantity Where StoreTransAction.TransID = 1 And StoreTransAction.ItemID=@itemID And StoreTransAction.StoreID=@StoreId And StoreTransAction.UnitID=@UnitID And StoreTransAction.StoresTransactionID=@StoresTransactionID; ", para, val);
dblQuantity = dblQuantity - Convert.ToDouble(row.ItemArray[2].ToString());
}
else
{
dataConnection UpdateQuantity = new dataConnection();
string[] paraelse = { "@dblQuntity", "@itemID", "@StoreId", "@UnitID", "@StoresTransactionID" };
object[] valelse = { dblQuantity, this.cboItemName.SelectedValue, this.cboStore.SelectedValue, this.cboUnits.SelectedValue, Convert.ToDouble(row.ItemArray[3].ToString()) };
UpdateQuantity.EditRecord("Update StoreTransAction SET StoreTransAction.quantity =[StoreTransAction].[quantity]-@dblQuntity Where StoreTransAction.TransID = 1 And StoreTransAction.ItemID=@itemID And StoreTransAction.StoreID=@StoreId And StoreTransAction.UnitID=@UnitID And StoreTransAction.StoresTransactionID=@StoresTransactionID;", paraelse, valelse);
dblQuantity = 0;
}
}
}