您好,我试图从数据库中获取特定列的数据,然后使用该数据减去..但是我收到一个错误,input string is not in a correct format.
我已经尝试了几乎所有我知道的东西,但是没有任何效果可以帮助我吗?
我的代码-
string t_qty = "";
SqlCommand cmd1 = new SqlCommand("select QTY from STOCK_ARRIVE where BARCODE = @barcode", d.con);
cmd1.Parameters.AddWithValue("@barcode", txt_barcode.Text);
d.con.Open();
SqlDataReader dr = cmd1.ExecuteReader();
while (dr.Read())
{
t_qty = dr["QTY"].ToString();
}
d.con.Close();
try
{
int less = 0;
less = int.Parse(t_qty) - int.Parse(txt_qty.Text);
SqlCommand cmd2 = new SqlCommand("update STOCK_ARRIVE set QTY=@pq where BARCODE=@barcode AND S_VC=@vc", d.con);
cmd2.Parameters.AddWithValue("@pq", less);
cmd2.Parameters.AddWithValue("@barcode", txt_barcode.Text);
cmd2.Parameters.AddWithValue("@vc", txt_vc.Text);
d.con.Open();
cmd2.ExecuteNonQuery();
d.con.Close();
}
catch (Exception ex)
{
Response.Write(ex);
}
Response.Write("<script>alert('Data has been saved')</script>");
答案 0 :(得分:0)
很可能您的cnversion int.Parse(t_qty)
失败了。而是尝试像使用TryParse()
int.TryParse(t_qty, out int quanrtity)