2012-07-08 2 views
0

SQL 서버에서 내 쿼리를 테스트하면 100 % 내 페이지가 작동하지 않습니다! 이 내 쿼리업데이트가 그리드 뷰 이벤트 업데이트에서 작동하지 않습니다

UPDATE Employee SET 
     Name='jojo', 
     Age=19, 
     GenderID=2, 
     CountryID=5, 
     Mobile=0917021092 
WHERE EmployeeID=10 

당신의 데이터 소스가 데이터 집합이기 때문에이 내 코드

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) 
     {    
      string s = GridView1.DataKeys[e.RowIndex].Value.ToString(); 

      Label id = (Label)GridView1.Rows[e.RowIndex].FindControl("lblEditID"); 
      Label EmployeeID = (Label)GridView1.Rows[e.RowIndex].FindControl("lblEmployeeID"); 
      TextBox name = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtEditName"); 
      TextBox age = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtEditAge"); 
      DropDownList gender = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("DropGender"); 
      DropDownList country = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("DropCountry"); 
      TextBox mobile = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtEditMobile"); 

      string stringconnectiong = ConfigurationManager.ConnectionStrings["Employee_TestConnectionString"].ConnectionString; 
      string sql = "update Employee set [email protected], [email protected],[email protected] , [email protected] , [email protected] where [email protected] AND [email protected]"; 

      SqlConnection con = new SqlConnection(stringconnectiong); 

      try 
      { 
      con.Open(); 
      SqlCommand cmd = new SqlCommand(); 
      cmd.Parameters.AddWithValue("@EmployeeID", EmployeeID.Text); 
      cmd.Parameters.AddWithValue("@ID", id.Text); 
      cmd.Parameters.AddWithValue("@Name", name.Text); 
      cmd.Parameters.AddWithValue("@Age", age.Text); 
      cmd.Parameters.AddWithValue("@GenderID", gender.SelectedValue); 
      cmd.Parameters.AddWithValue("@CountryID", country.SelectedValue); 
      cmd.Parameters.AddWithValue("@Mobile", mobile.Text); 
      cmd.CommandType = CommandType.Text; 
      cmd.CommandText = sql; 
      cmd.Connection = con; 
      cmd.ExecuteNonQuery(); 
      SqlDataAdapter dr = new SqlDataAdapter(cmd); 
      DataSet ds = new DataSet(); 
      dr.Fill(ds); 
      GridView1.DataSource = ds; 
      GridView1.EditIndex = -1; 
      BindGridview(); 

     } 

     catch (System.Data.SqlClient.SqlException ex) 
     { 
      string msg = "Error Updating "; 
      msg += ex.Message; 
      throw new Exception(msg); 
     } 

     finally 
     { 
      con.Close(); 
      con.Dispose(); 
      BindGridview(); 
     } 

    } 
+0

코드가 작동 할 때까지 try catch를 추가하지 마십시오. 어떤 오류 메시지가 먼저 생성되는지 확인하십시오 ... – IrishChieftain

답변

0

, 당신은 당신이 DataMember를의 때에 프로퍼티를 통해 사용중인 데이터 세트 내에있는 데이터 테이블을 지정해야합니다. 또는 데이터 테이블을 데이터 소스로 사용하십시오.

는 다음과 같이 데이터 세트 라인을 교체 : 또한

DataTable dt = new DataTable(); 
dr.Fill(dt); 
GridView1.DataSource = dt; 

GridView1_RowUpdated 이벤트를 사용합니다. GridView1_RowUpdating 이벤트가 발생하면 전에 테이블이 업데이트되므로 매개 변수 값이 아직 업데이트되지 않았습니다.

+0

제발 어떻게 말해주십시오 ??? –

+0

@MohannedKhaledMaglad, 나는 데이터 세트 대신 데이터 테이블을 사용하는 방법을 보여주기 위해 나의 대답을 편집했다. –

+0

그것은 또한 작동하지 않습니다 ?? –

관련 문제