943,777 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 4886
  • ASP.NET RSS
Sep 4th, 2008
0

gridview rowupdating using parametrized query.

Expand Post »
Hi

I have gridview and I am using gridview1_rowupdating event to update the gridview, but when I am using the code given below its not working. I do not know why it is not updating, it is not even showing error. please help me resolve this problem.
Thanks
aspnet Syntax (Toggle Plain Text)
  1. protected void gv_RowUpdating1(object sender, GridViewUpdateEventArgs e)
  2. {
  3. connectAccessDb();
  4. int i = e.RowIndex;
  5. //par = cmd.Parameters;
  6. //cmd.Parameters.Clear();
  7. string id = (gv.Rows[e.RowIndex].FindControl("lblCID") as Label).Text;
  8. string comp = (gv.Rows[e.RowIndex].FindControl("txtCName") as TextBox).Text;
  9. string address = (gv.Rows[e.RowIndex].FindControl("txtCAddr") as TextBox).Text;
  10. string city = (gv.Rows[e.RowIndex].FindControl("txtCcity") as TextBox).Text;
  11. //string strQuery="UPDATE companydetail SET companyname='" + comp + "',companyaddress='" + address + "',companycity='" + city + "' where id=" + Convert.ToInt32(id);
  12. //dCmd = new OleDbCommand(strQuery, cn);
  13. //dCmd = new OleDbCommand("UPDATE companydetail SET companyname=@comp, companyaddress=@address, companycity=@city where id=@id", cn);
  14. string strQuery = "UPDATE companydetail SET companyname=@comp, companyaddress=@address, companycity=@city where id=@id";
  15. cmd = new OleDbCommand(strQuery, cn);
  16. cmd.Parameters.Add("@id", OleDbType.Integer).Value = Convert.ToInt32(id);
  17. cmd.Parameters.Add("@comp", OleDbType.VarChar).Value = comp;
  18. cmd.Parameters.Add("@address", OleDbType.VarChar).Value = address;
  19. cmd.Parameters.Add("@city", OleDbType.VarChar).Value = city;
  20.  
  21. cmd.ExecuteNonQuery();
  22. cmd.ExecuteNonQuery();
  23. //gv.EditIndex = -1;
  24. cn.Close();
  25. bindData();
  26.  
  27.  
  28. }
  29. private void bindData()
  30. {
  31. connectAccessDb();
  32. da = new OleDbDataAdapter("SELECT id,companyname,companyaddress,companycity from companydetail order by companyname", cn);
  33. da.Fill(ds, "companydetail");
  34. gv.DataSource = ds;
  35. gv.DataBind();
  36. cn.Close();
  37. }
  38. private void connectAccessDb()
  39. {
  40.  
  41. cn = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=" + strRootDir + "App_Data\\newsdb.mdb");
  42. cn.Open();
  43. }
Last edited by cscgal; Sep 4th, 2008 at 2:22 pm. Reason: Added code tags
Reputation Points: 10
Solved Threads: 0
Light Poster
ansari.wajid is offline Offline
47 posts
since Aug 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: How to initialize ASP.Net Gridview
Next Thread in ASP.NET Forum Timeline: Page refresh





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC