2012-01-04 3 views
1

작동하지 않는 레코드를 업데이트하기위한 간단한 저장 프로 시저를 작성했지만 이유가 없습니다. 예외는 발생하지 않지만 레코드도 업데이트되지 않습니다. 아래C#에서 호출 한 저장 프로 시저가 레코드를 업데이트하지 않습니다.

참조 코드 : SQL Server의

public int IMGId; 

protected void btnUpdate_Click(object sender, EventArgs e) 
    { 
     string result = ""; 
     string sSQL = "usp_imageloader_update"; 


     using (SqlConnection dbConnection = new SqlConnection(CKS_app_settings.sql_conn_string_db)) 
     { 
      // SqlTransaction tn=null; 
      try 
      { 
       dbConnection.Open(); 
       //start Transaction 
       // tn = dbConnection.BeginTransaction(); 
       SqlCommand command = new SqlCommand(sSQL, dbConnection); 
       //command.Transaction = tn; 
       command.CommandText = sSQL; 
       command.CommandType = CommandType.StoredProcedure; 
       command.CommandTimeout = 1024; 
       command.Parameters.AddWithValue("@p_image_id", IMGId); 
       command.Parameters.AddWithValue("@p_url", txtUrl.Text); 
       command.Parameters.AddWithValue("@p_alt_text", txtAlt.Text); 
       //command.Parameters.AddWithValue("@p_filepath", File1.Value); 
       //command.Parameters.AddWithValue("@p_cntr_id", str_id); 
       int rowsAffected = command.ExecuteNonQuery(); 
      } 
      catch (SqlException ex) 
      { 
       // throw ex; 

       //If it failed for whatever reason, rollback the //transaction 
       //tn.Rollback();       
       //No need to throw because we are at a top level call and //nothing is handling exceptions 
       result = ex.InnerException.Message; 
      } 
     } 

저장 프로 시저가

USE [smsdb_test_griffin2] 
GO 
/****** Object: StoredProcedure [dbo].[usp_imageloader_update] Script Date: 01/04/2012 09:05:41 ******/ 
SET ANSI_NULLS ON 
GO 
SET QUOTED_IDENTIFIER ON 
GO 
ALTER procedure [dbo].[usp_imageloader_update] 
@p_image_id INT, 
@p_url VARCHAR(255), 
@p_alt_text VARCHAR(255) 
as 

UPDATE Image_Library_UK 
SET 
[email protected]_url, 
[email protected]_alt_text 

WHERE [email protected]_image_id 
+7

SP를 C# 코드가 아닌 별도로 실행하면 작동합니까? – razlebe

+0

T-SQL 말씀 하시겠습니까? GO는 T-SQL의 저장 프로 시저에서 작동하지 않습니다. –

+0

SQL Managament에서 exec 프로 시저를 C#으로 전달 된 값으로 시도 했습니까? – Mariusz

답변

1

이 작동하는지 가정, 고립에서 그것을 시도 데 (아무것도 눈부시게 명백한 잘못이 없다), I 매개 변수 중 하나가 올바르게 설정되지 않았다고 가정합니다. IMGid가 맞지 않을 수 있습니다 -이 효과가있을 것입니다 - 또는 그것은 URL과 alttext가 이미 페이지의 부하에 의해 그들의 값으로 재설정 될 수 있습니다.

통화 시점의 값을 확인하십시오. ! Page.IsPostBack을 사용하여 포스트 백에서이 값을 재설정하지 않아도됩니다. 요청 변수를 사용하여 액세스해야 할 수도 있습니다. 나머지 코드에 따라 다릅니다.

+0

ID의 int 값을 하드 코딩 했으므로 저장 프로 시저가 작동했습니다. 내 코드에서 이드를 잡을 때 뭔가 잘못되었다고 생각합니다. 도와 주신 모든 분들께 감사드립니다! –

관련 문제