Code:
public void Update_Stock(Inseed Is)
{
if (con.State == ConnectionState.Open)
{
con.Close();
}
try
{
string str = "Select CurrStock from StockInMaster where Name = '" + Is.ProductName+ "'";
Int64 Units = 0;
SqlCommand cmd = new SqlCommand(str, con);
con.ConnectionString = cnstr;
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
if (dr["CurrStock"].ToString() == "0")
{
Units = 0;
}
else
{
Units = Convert.ToInt64(dr[0]) - Is.Quantity; // Error is in this line(Cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?)
}
}
string str1 = "Update StockInMaster set CurrStock = " + Units +
" where Name = '" + Is.ProductName + "'";
SqlCommand cmd1 = new SqlCommand(str1,con);
cmd1.ExecuteNonQuery();
cmd1.Dispose();
con.Close();
}
catch (Exception ex)
{
throw new Exception(ex.Message.ToString());
}
}
Comment