2

我对 ASP.NET 技术很陌生,我偶然发现了我的应用程序的特殊问题。每当用户单击 RadGridView 数据行上的按钮时,我都会尝试更新布尔数据库列以将值设置为 True (1)。该按钮似乎工作正常,因为没有错误或异常,但是数据库列根本没有更新。

这是我的代码片段:

ASPX:

<telerik:GridButtonColumn ButtonType="PushButton" ConfirmTextFields="TrxId" 
                    ConfirmTextFormatString="Are you sure you want to release Order No. {0}?" 
                    CommandName="btnRelease" Text="Release Order">
                </telerik:GridButtonColumn>

C# :

protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == "btnRelease")
        {
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ZEUS"].ConnectionString);

            con.Open();
            SqlCommand command = new SqlCommand("UPDATE [TransactsData] SET [IsReleased] = 1, [TimeReleased] = GETDATE() WHERE [TrxId] = @TrxId", con);
            command.Parameters.AddWithValue("@TrxId", SqlDbType.BigInt);
            command.ExecuteNonQuery();
            con.Close();
        } 
    }

提前致谢。

4

2 回答 2

3

尝试这个:

protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == "btnRelease")
    {
        GridDataItem item = (GridDataItem)e.Item; 

        // Replace "TrxId" with the reference to the item containing your TrxId
        string TrxId = item["TrxId"].Text;

        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ZEUS"].ConnectionString);

        con.Open();
        SqlCommand command = new SqlCommand("UPDATE [TransactsData] SET [IsReleased] = 1, [TimeReleased] = GETDATE() WHERE [TrxId] = @TrxId", con);
        command.Parameters.AddWithValue("@TrxId", TrxId);
        command.ExecuteNonQuery();
        con.Close();
    } 
}

顺便说一句:我假设你的 RadGrid 中有这样的东西:

<telerik:GridBoundColumn DataField="TrxId" HeaderText="Transaction ID" UniqueName="TrxId"> 
于 2013-07-23T08:57:42.523 回答
1

像这样试试。我认为您错过了@TrxId 的价值

var TrxId = 10;//The value of @TrxId parameter
command.Parameters.Add(new SqlParameter("@TrxId",TrxId));

或者像这样

var TrxId = 10;//The value of @TrxId parameter
command.Parameters.AddWithValue("@TrxId",TrxId);
于 2013-07-23T08:51:52.233 回答