c# - Simple shopping cart : calculating total price (logic) -
i have 2 dropdownlists category , product, , 2 label controls price , subtotal , textbox control quantity. when select category, other dropdownlist product add products depending on category , when select product, label (price , subtotal) , textbox (qunatity) values depending on product. , when change quantity, subtotal changed depending on value of quantity.
problem below method
protected void calculatetotal() { string cnnstring = configurationmanager.connectionstrings["connectionstring1"].connectionstring; sqlconnection conn = new sqlconnection(cnnstring); conn.open(); sqlcommand cmd1 = new sqlcommand("select * cart", conn); sqldatareader dr = cmd1.executereader(); lblsubtotal.text = convert.tostring(total); conn.close() }
if want 1 value query can use executescalar
protected void calculatetotal() { string cnnstring = configurationmanager.connectionstrings["connectionstring1"].connectionstring; sqlconnection conn = new sqlconnection(cnnstring); conn.open(); sqlcommand cmd1 = new sqlcommand("select sum (quantity * price) cart", conn); lblsubtotal.text = convert.tostring(cmd1.executescalar()); conn.close() }
Comments
Post a Comment