문제

I have an event that fires on a button click that calls a stored procedure that deletes the selected row from the database.

In debugging this I have already hard coded the stored procedure with an id to make sure the delete was working on SQL side so I wont post the stored procedure. I also went into my page and on selecting the record to delete made sure that the hidden field was being set to the id of the record.

When I click I see the post back occur so I see the button firing, and it may be something small and stupid with my code or a permissions issue I am not aware of or where to look for.

The parameter for the stored procedure is an integer, and I am not hitting the catch or throwing errors of any kind the data just is not being deleted.

Thanks for any help on this issue as always it is much appreciated.

This is the code that fires when the button is clicked.

if (isAdmin)
{
    SqlConnection cnx = new SqlConnection(server);
    SqlCommand cmd = new SqlCommand("STOREDPROCNAME", cnx);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("@VARIABLEFORPROC", Convert.ToInt16(hiddenfield1.Value.ToString()));

    try
    {
       cnx.Open();
       cmd.ExecuteNonQuery();
       cnx.Close();
    }
    catch (Exception ex)
    {
       throw new Exception("Error executing MyProcedureName.", ex);
    }
}

fillDataGrids();
도움이 되었습니까?

해결책

The SQL Int type maps to the C# Int32 type. It's possible that you're getting data loss during your conversion. Try replacing

cmd.Parameters.AddWithValue("@VARIABLEFORPROC", Convert.ToInt16(hiddenfield1.Value.ToString()));

with

cmd.Parameters.AddWithValue("@VARIABLEFORPROC", Convert.ToInt32(hiddenfield1.Value.ToString()));

다른 팁

you must to try the stored procedure accuracy in SQL after than try it on a transaction and log the exception on the DB you must be sure where is the error happening

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top