0

in the update query its giving an exception as Operand data type varchar is invalid for subtract operator
so pls help me how to solve this

da7 = new SqlDataAdapter("SELECT     item_name, item_quan,item_cat FROM         c_item WHERE     (item_name = '" + fname + "') AND (item_cat = '1')", con);
            da7.Fill(dt7);
            string mname = dt7.Rows[0][0].ToString();
            int quan = Convert.ToInt32(dt7.Rows[0][1].ToString())
 string qu = (string)(Session["u"]);
            int quantity = Convert.ToInt32(qu);

if (fname == "Singam")
                {
                    da5 = new SqlDataAdapter("update c_order set cust_id='" + cid + "',fname='" + fname + "',oname='" + oname.Text + "',pinno='" + pinno.Text + "',validity='" + dtProjectStartDate + "',tdate='" + DateTime.Now.ToShortDateString() + "' where cust_id='" + cid + "' and order_id='" + order3 + "'  ", con);
                    da8 = new SqlDataAdapter("[B]update c_item set item_quan = '"+quan+"' - '"+quantity+"' where item_name = '" + fname + "' and item_cat='1' [/B]", con);
                    da8.Fill(dt8);
                }

Edited by __avd: Added [code] tags.

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by searchsource
0
da8 = new SqlDataAdapter("update c_item set item_quan =" + quan + "-" + quantity + " where item_name = '" + fname + "' and item_cat='1'", con);
0

da8 = new SqlDataAdapter("update c_item set item_quan =" + quan + "-" + quantity + " where item_name = '" + fname + "' and item_cat='1'", con);

you should first convert quan,quantity to integer data type . later it you can perform subtract operation.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.