Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从C#不';更新记录_C#_Asp.net_Sql Server_Tsql_Stored Procedures - Fatal编程技术网

从C#不';更新记录

从C#不';更新记录,c#,asp.net,sql-server,tsql,stored-procedures,C#,Asp.net,Sql Server,Tsql,Stored Procedures,我已经编写了一个简单的存储过程来更新一个不起作用的记录,但我不知道为什么。不会引发异常,但记录也不会更新 见下面的代码: public int IMGId; protected void btnUpdate_Click(object sender, EventArgs e) { string result = ""; string sSQL = "usp_imageloader_update"; using (SqlConnectio

我已经编写了一个简单的存储过程来更新一个不起作用的记录,但我不知道为什么。不会引发异常,但记录也不会更新

见下面的代码:

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;
            }
        }
SQL SERVER中的存储过程

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  
Url=@p_url,
Alt_text=@p_alt_text 

WHERE Image_id=@p_image_id

在单独尝试之后,假设这是可行的(并且没有明显的错误),我会假设您的一个参数设置不正确。可能是IMGid不正确——这会产生这种效果——也可能是url和alttext的值已经被页面加载重置为它们的值


检查调用点的值。它可能是你需要使用的!Page.IsPostBack不在回发时重置这些值。您可能需要使用request变量来访问它们,这取决于代码的其余部分。

在单独尝试之后,假设这是可行的(并且没有明显的错误),我会假设您的一个参数设置不正确。可能是IMGid不正确——这会产生这种效果——也可能是url和alttext的值已经被页面加载重置为它们的值


检查调用点的值。它可能是你需要使用的!Page.IsPostBack不在回发时重置这些值。您可能需要使用request变量访问它们,这取决于代码的其余部分。

如果您单独执行SP,即不是从您的C#code?T-SQL执行SP,它是否工作?GO在t-SQL中的存储过程中不起作用。您是否尝试过在SQL管理中使用C#中传递的值执行exec过程?可能是btnUpdate的单击处理程序被重置/取消设置。“UPDATE Image_Library_UK”更新表。如果您单独执行,即不是从C#代码执行,SP是否工作?您是说t-SQL吗?GO在t-SQL中的存储过程中不起作用。您是否尝试过SQL管理中的exec过程,并使用C#中传递的值?可能是btnUpdate的单击处理程序被重置/取消设置。“UPDATE Image_Library_UK”更新表。我为ID硬编码了一个int值,存储过程正常工作。我猜从我的代码中获取id时出错了。感谢所有帮助过我的人!我为ID硬编码了一个int值,存储过程正常工作。我猜从我的代码中获取id时出错了。感谢所有帮助过我的人!