작동하지 않는 레코드를 업데이트하기위한 간단한 저장 프로 시저를 작성했지만 이유가 없습니다. 예외는 발생하지 않지만 레코드도 업데이트되지 않습니다. 아래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
SP를 C# 코드가 아닌 별도로 실행하면 작동합니까? – razlebe
T-SQL 말씀 하시겠습니까? GO는 T-SQL의 저장 프로 시저에서 작동하지 않습니다. –
SQL Managament에서 exec 프로 시저를 C#으로 전달 된 값으로 시도 했습니까? – Mariusz