How to check a column value in a table and update that value
Hi friends..
I have to check a column value in a table , and i want to update that value. My coding and table structure is below. It shows syntax error at where condition in else statement.
also...while checking with break point it enters into else condition and shows syntax error near Where.
string strSQL3 = "SELECT PurchaseRtn_Qty FROM [Stock] where [ItemName]='" + txtDescription.Text + "' and [BatchNo]='" + txtBatchNo.Text + "'";
SqlCommand cmdStockQty = new SqlCommand(strSQL3, sqlConn);
object Qty = cmdStockQty.ExecuteScalar();
if (Qty == DBNull.Value)
{
string strSQL2 = "Update [Stock] set [PurchaseRtn_Qty]=" +txtQty.Text+ " where [ItemName]='" + txtDescription.Text + "' and [BatchNo]='" + txtBatchNo.Text + "'";
SqlCommand cmdStock = new SqlCommand(strSQL2, sqlConn);
cmdStock.ExecuteNonQuery();
}
else
{
string strSQL2 = "Update [Stock] set [PurchaseRtn_Qty]=[PurchaseRtn_Qty]+ "+txtQty.Text+" where [ItemName]='" + txtDescription.Text + "' AND [BatchNo]='" + txtBatchNo.Text + "'";
SqlCommand cmdStock = new SqlCommand(strSQL2, sqlConn);
cmdStock.ExecuteNonQuery();
}
i checked like below also:
string strSQL2 = "Update [Stock] set [PurchaseRtn_Qty]=(PurchaseRtn_Qty)+ '" + (Convert.ToInt32(txtQty.Text)) + "' where [ItemName]='" + txtDescription.Text + "' and [BatchNo]='" + txtBatchNo.Text + "'";
its firing but t value is not updated from null. Anyone help me please....Its urgent....
CREATE TABLE [dbo].[Stock](
[ItemCode] [nvarchar](50) NULL,
[ItemName] [nvarchar](100) NULL,
[BatchNo] [nvarchar](50) NULL,
[ExpiryDate] [datetime] NULL,
[SalesRate] [float] NULL,
[MRP] [float] NULL,
[PurchaseRate] [float] NULL,
[Opening_Qty] [int] NULL,
[Closing_Qty] [int] NULL,
[Purchase_Qty] [int] NULL,
[Sales_Qty] [int] NULL,
[PurchaseRtn_Qty] [int] NULL,
[SalesRtn_Qty] [int] NULL,
[Issue_Qty] [int] NULL,
[Return_Qty] [int] NULL,
[Opening_Value] [float] NULL,
[Purchase_Value] [float] NULL,
[Closing_Value] [float] NULL,
[Sales_Value] [float] NULL,
[SalesRtn_Value] [float] NULL,
[PurchaseRtn_Value] [float] NULL,
[VatPer] [float] NULL
) ON [PRIMARY]