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);
                }

Recommended Answers

All 2 Replies

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.