Doubt in adding data in database in c#
Hi... I am new in C#. I am doing a billing project. I have one doubt. In my form i have text box. for sales entry. when i enter in that text box it have to be added to my database in the field of sales. For example in my database for an item pen it already have sales value 5 in database. if i enter again 5 in text box my database value should be 10. I don't know what to do... so please help me
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Biswa Pujarini MohapatraRank #463 · 5.4K pointsPosted Feb 14, 2014, 7:43 PM EST
ASpx.cs
protected void Button1_Click(object sender, EventArgs e) { string connectionString = "Persist Security Info=False;User ID=sa;Password=123;Initial Catalog=SalesDB";//TODO change your connection string using (SqlConnection con = new SqlConnection(connectionString)) { string SqlQuery =""; SqlCommand cmd = new SqlCommand("Insert into table (sale) values(SUM(@sale))", con);//To DO change your table and columna name con.Open(); if (con.State == ConnectionState.Open) { cmd.Parameters.Add("@sale", SqlDbType.Int).Value = txtSales.Text; try { cmd.ExecuteNonQuery(); con.Close(); } catch(SqlException ex) { throw ex; } } }