2009-07-08 2 views
0
protected void DetailsView1_ItemInserted(object sender, EventArgs e) 
{ 
    using (SqlCommand cmd2 = new SqlCommand("uspUpdateDisplayHours", cn)) 
     { 
      cn.Open(); 
      cmd2.CommandType = CommandType.StoredProcedure; 
      cmd2.ExecuteNonQuery(); 
      cn.Close(); 
     } 
     DetailsView1.DataBind(); 
    } 
} 

저장 프로 시저가 SQL Server에서 작동하고 있습니다 - 양식에있는 열 1 업데이트 중입니다. 아니요. 오류없이 .net에서 결과/데이터를 표시하지 않습니다.페이지를 새로 고치거나 데이터 바인딩하지 않습니다. linq 데이터 소스를 새로 고치는 방법?

+2

저장 프로 시저가 무엇을 반환해야합니까? –

+0

Dreas 승/동의 : "작동하지 않음"을 정의하십시오. – Eric

+0

함수가 실행되고 있습니까? 어딘가에 중단 점을 놓으십시오. –

답변

0

저장 프로 시저가 실행 중이지만 DataSource를 새로 고치는 원인이되는 결과가 저장 프로 시저에 사용되지 않는 것 같습니다. 실제로 데이터 바인딩을 위해 저장 프로 시저를 실행 한 후에는 데이터베이스에서 무언가를 얻어야합니다. 데이터를 다시 가져 오는

간단한 예 :

protected void DetailsView1_ItemInserted(object sender, EventArgs e) 
{ 
    using (SqlCommand cmd2 = new SqlCommand("uspUpdateDisplayHours", cn)) 
    using (SqlDataAdapter adapter = new SqlDataAdapter(cmd2))   
     { 
      var dataSet = new DataSet(); 
      cn.Open(); 
      cmd2.CommandType = CommandType.StoredProcedure; 
      adapter.Fill(dataSet); 
      var _result = //get to your result some how. 
      DetailsView.DataSource = result; 
      cn.Close(); 
     } 
     DetailsView1.DataBind(); 
    } 
} 

난 정말이 일을 권하고 싶지 않다. 나는 당신이 당신의 DetailsView가 당신이 기대하는 데이터로 새로 고쳐지지 않는 이유를 설명하기 위해서 이것을 보여줄뿐입니다.

0

난 그냥 여기 추측하지만, 어떻게 이런 일에 대해 해요 : 위의 예에서

protected void DetailsView1_ItemInserted(object sender, EventArgs e) 
{ 
    DataSet ds = new DataSet(); 
    using (SqlCommand cmd2 = new SqlCommand("uspUpdateDisplayHours", cn)) 
    { 
     cmd2.CommandType = CommandType.StoredProcedure; 
     new SqlDataAdapter(cmd2).Fill(ds); 
    } 
    DetailsView1.DataSource = ds; 
    DetailsView1.DataBind(); 
    } 
} 

, 난 당신이 SP에서 뭔가를 반환 할 것을 가정하고있다. (이로드 될 때 양식을 채워 때와 같은)


그냥 데이터베이스에서 데이터로 위해 DetailsView를 업데이트하려면

, 그냥 다시 그 방법을 실행합니다.

void PopulateForm() { 
    //get data from database and bind it to the ListView 
} 

protected void DetailsView1_ItemInserted(object sender, EventArgs e) 
{ 
    // <= here run the uspUpdateDisplayHours sp 

    PopulateForm(); //run this method method again so that the data is refreshed   
} 
+0

당신은 바로 sp에서 뭔가를 반환하고 싶습니다. 양식 (.net)에서 업데이트 한 후 여전히 데이터가 업데이트되지 않았습니다. 그런데 Form (.net)으로 돌아 가면 업데이트 된 데이터가 표시됩니다. 양식 (.net)을 새로 고치는 것이 아닙니다. help ~ – Yves

0

ExecuteNonQuery은 데이터베이스 삽입, 삭제, 업데이트를 업데이트하는 데 사용해야합니다.

ExecuteReader을 사용하면 결과가 SqlDataReader 개체에 반환됩니다.

+0

나는 ExecuteReader를 시도했다. Form (.net)에서 업데이트 한 후 업데이트 된 데이터가 여전히 표시되지 않는다. 그런데 Form (.net)으로 돌아 가면 업데이트 된 데이터가 표시됩니다. 양식 (.net)을 새로 고치는 것이 아닙니다. 도와 ~ – Yves

관련 문제