我无法在gridView中更新行中的数据..没有显示错误,也没有显示更新的行 [英] I am not able to update Data in Row in gridView ..Not showing error and also not showing updated row

查看:77
本文介绍了我无法在gridView中更新行中的数据..没有显示错误,也没有显示更新的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想更新My GridView控件的行

我可以编辑但是更新的数据没有反映在数据库中以及UI。



以下是我的代码



Hi,
I want to update row of My GridView Control
I am able to edit but updated data is not reflecting in database as well as UI.

Here Below is my code

protected void UpdateEmployee(object sender, GridViewUpdateEventArgs e)

       {

           TextBox EmployeeID =(TextBox)GridView1.Rows[e.RowIndex].FindControl("txtEmployeeID");

           TextBox EnterpriseID = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtEnterpriseID");

           TextBox EmployeeName = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtEmployeeName");

           TextBox Hobbies = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtHobbies");

           TextBox ContactDetails = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtContactDetails");

           TextBox Details = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtDetails");

           using (SqlConnection Sqlcon = new SqlConnection(strCon))
           {

               using (SqlCommand cmd = new SqlCommand())
               {
                   Sqlcon.Open();
                   cmd.Connection = Sqlcon;
                   cmd.CommandType = CommandType.StoredProcedure;
                   cmd.CommandText = "spEmployee";
                   cmd.Parameters.Add(new SqlParameter("@ActionId", SqlDbType.VarChar, 15));
                   cmd.Parameters.Add(new SqlParameter("@EmployeeID", SqlDbType.BigInt));
                   cmd.Parameters.Add(new SqlParameter("@EnterpriseID", SqlDbType.VarChar, 25));
                   cmd.Parameters.Add(new SqlParameter("@EmployeeName",SqlDbType.VarChar,50));
                   cmd.Parameters.Add(new SqlParameter("@Hobbies", SqlDbType.VarChar, 50));
                   cmd.Parameters.Add(new SqlParameter("@ContactDetails", SqlDbType.BigInt));
                   cmd.Parameters.Add(new SqlParameter("@Details", SqlDbType.VarChar, 50));
                   cmd.Parameters["@ActionId"].Value = "UPDATE";
                   cmd.Parameters["@EnterpriseID"].Value = EnterpriseID.Text.Trim();
                   cmd.Parameters["@EmployeeName"].Value = EmployeeName.Text.Trim();
                   cmd.Parameters["@Hobbies"].Value = Hobbies.Text.Trim();
                   cmd.Parameters["@Details"].Value = Details.Text.Trim();
                   cmd.ExecuteNonQuery();
               }
               GridView1.EditIndex = -1;

               lblMessage.Text = "Record updated successfully!";

           }

       }


       RowCancelingEdit="CancelEdit"
       OnRowEditing="EditEmployee"
       OnRowUpdating="UpdateEmployee"

推荐答案

检查出来:插入,更新,删除Gridview ......简单方法 [ ^ ]


这篇关于我无法在gridView中更新行中的数据..没有显示错误,也没有显示更新的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆