How to sum two values in sql server2008
Hi frnds,
I have to select a column value from a table and with that i have to sum another value using c#.net
i m selecting like this
string dbConn = ConfigurationManager.ConnectionStrings["CMC"].ConnectionString;
SqlConnection sqlConn = new SqlConnection(dbConn);
sqlConn.Open();
DateTime ExDate = DateTime.ParseExact(txtExpiryDate.Text, "dd-MM-yyyy", CultureInfo.InvariantCulture);
string strSQL2 = "select [Opening_Qty] from [Stock] where [ItemName]='" + txtItemName.Text + "' AND [BatchNo]='" + txtBatchNo.Text + "' AND [ExpiryDate]='" + ExDate + "'";
SqlCommand cmdUpdate = new SqlCommand(strSQL2, sqlConn);
SqlDataReader drOpeningBalance = cmdUpdate.ExecuteReader();
if (drOpeningBalance.Read())
{
string OpeningQty = drOpeningBalance[0].ToString();
}
and
string strSQL1 = " Update [Stock] set [Opening_Qty]='" +( OpeningQty +(Convert.ToInt32(txtQty.Text)))+ "' where [ItemName]='" + txtItemName.Text + "' and [BatchNo]='" + txtBatchNo.Text + "'";
SqlCommand commandReader = new SqlCommand(strSQL1, sqlConn);
commandReader.ExecuteNonQuery();
like above lines i m summing up two values ...But its not working...Any suggestion pls...