Hi!
i want to update my database table on button click event. here is the query.
protected void Button4_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("update Arrear set ConsumerNo=" + ConsumerNo.Text + ",WaterCharges='" + WaterCharges.Text + "',SaverageCharges='" + SaverageCharges.Text + "',ConservancyCharges='" + SaverageCharges.Text + "',arear='" + arear.Text + "' where ConsumerNo=" + ConsumerNo.Text, con);
con.Close();
}
but it does not update the table. please tell me what is the problem
Loading

Mayur GujrathiRank #666 · 3.6K reputationPosted Jun 1, 2011, 10:21 PM EDT
Posted Jun 1, 2011, 9:46 PM EDT
The best way , start the sql profiler/ just copy the cmd text (while debuggin), and paste it in sql query window and see why it is not updating...
The reason could the where clause value (consumerNo) also.
saifullah khanRank #4,887 · 320 reputationPosted Jun 1, 2011, 9:58 PM EDT
secondly i am using sql 2008R2. i tried alot but not found the sql profiler. could you please tell me where it is???
Suthish NairRank #92 · 22.8K reputationPosted Jun 1, 2011, 9:59 PM EDT
You must use Parameterized Queries..
Refer articles..
Parameterized Query and SQL Injection Attacks
Link
Posted Jun 1, 2011, 10:03 PM EDT
Mayur GujrathiRank #666 · 3.6K reputationPosted Jun 2, 2011, 2:09 AM EDT