| | |
gridview rowupdating using parametrized query.
Please support our ASP.NET advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Aug 2007
Posts: 33
Reputation:
Solved Threads: 0
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
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)
protected void gv_RowUpdating1(object sender, GridViewUpdateEventArgs e) { connectAccessDb(); int i = e.RowIndex; //par = cmd.Parameters; //cmd.Parameters.Clear(); string id = (gv.Rows[e.RowIndex].FindControl("lblCID") as Label).Text; string comp = (gv.Rows[e.RowIndex].FindControl("txtCName") as TextBox).Text; string address = (gv.Rows[e.RowIndex].FindControl("txtCAddr") as TextBox).Text; string city = (gv.Rows[e.RowIndex].FindControl("txtCcity") as TextBox).Text; //string strQuery="UPDATE companydetail SET companyname='" + comp + "',companyaddress='" + address + "',companycity='" + city + "' where id=" + Convert.ToInt32(id); //dCmd = new OleDbCommand(strQuery, cn); //dCmd = new OleDbCommand("UPDATE companydetail SET companyname=@comp, companyaddress=@address, companycity=@city where id=@id", cn); string strQuery = "UPDATE companydetail SET companyname=@comp, companyaddress=@address, companycity=@city where id=@id"; cmd = new OleDbCommand(strQuery, cn); cmd.Parameters.Add("@id", OleDbType.Integer).Value = Convert.ToInt32(id); cmd.Parameters.Add("@comp", OleDbType.VarChar).Value = comp; cmd.Parameters.Add("@address", OleDbType.VarChar).Value = address; cmd.Parameters.Add("@city", OleDbType.VarChar).Value = city; cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery(); //gv.EditIndex = -1; cn.Close(); bindData(); } private void bindData() { connectAccessDb(); da = new OleDbDataAdapter("SELECT id,companyname,companyaddress,companycity from companydetail order by companyname", cn); da.Fill(ds, "companydetail"); gv.DataSource = ds; gv.DataBind(); cn.Close(); } private void connectAccessDb() { cn = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=" + strRootDir + "App_Data\\newsdb.mdb"); cn.Open(); }
Last edited by cscgal; Sep 4th, 2008 at 2:22 pm. Reason: Added code tags
![]() |
Other Threads in the ASP.NET Forum
- Previous Thread: How to initialize ASP.Net Gridview
- Next Thread: search sql database textbox.text
Views: 2832 | Replies: 0
| Thread Tools | Search this Thread |
Tag cloud for ASP.NET
.net 2.0 3.5 activexcontrol advice ajax asp asp.net beginner bottomasp.net browser businesslogiclayer button c# c#gridviewcolumn checkbox child class click compatible confirmationcodegeneration content contenttype control countryselector courier css database datagrid datagridview datalist deadlock deployment development dgv dropdown dropdownmenu dynamic edit embeddingactivexcontrol feedback findcontrol flash flv folder form forms grid gridview homeedition hosting identity iframe iis index javascript jquery languages list maps menu mobile mono mssql multistepregistration nameisnotdeclared novell object objects order problem profile ratings refer rotatepage search security serializesmo.table silverlight smartcard sql ssl tracking treeview typeof update validation vb vb.net view virtualdirectory vista visual-studio visualstudio vs2008 web webarchitecture webdevelopment wizard xml





