0

Hi all,

I have a page on which I've done several successful ExecuteNonQuery calls that added new rows to existing tables. But one, despite all the parameters being correct and receiving a positive return value and also a valid output parameter, seems to have no effect on the database. Several tables should have new rows, but none of them do. I'm using similar code for all database calls. Here's the ADO code:

SqlConnection con = GetConnection();
using (SqlCommand cmd = con.CreateCommand())
{
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.CommandText = "spAddTask";
    cmd.Parameters.Add("@RequestorID", SqlDbType.Int).Value = ddlRequestors.SelectedValue;
    cmd.Parameters.Add("@ReportTopicID", SqlDbType.Int).Value = ddlReportTopics.SelectedValue;
    cmd.Parameters.Add("@BusinessTypeID", SqlDbType.Int).Value = ddlBusinessTypes.SelectedValue;
    cmd.Parameters.Add("@DueDate", SqlDbType.DateTime).Value = txtDueDate.Text;
    cmd.Parameters.Add("@Priority", SqlDbType.VarChar).Value = ddlPriority.SelectedValue;
    cmd.Parameters.Add("@RequestorNarration", SqlDbType.VarChar).Value = txtDescription.Text;
    SqlParameter prmTaskID = cmd.Parameters.Add("@TaskID", SqlDbType.Int);
    prmTaskID.Direction = ParameterDirection.Output;
    con.Open();
    int z = cmd.ExecuteNonQuery(); //Returns 2
    con.Close();

    int taskID = Convert.ToInt32(prmTaskID.Value);
}

Any idea of how this can happen? Thanks in advance.
-Eric

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by eorns
0

i was facing the same problem last week. i was passing one of parameter incorrect

e.g.
cmd.Parameters.Add("@RequestorNarration", SqlDbType.VarChar).Value = txtDescription.Text;

0

Thanks for your reply. I'm pretty sure all the parameter values are correct. I checked them while stepping through the code. Like I said, I get a positive return value and I get a valid value for the output parameter @TaskID (the next TaskID). But then there is no Task in my table with that ID.

0

As it turned out, there was an error in my stored procedure. Ironically, it wasn't that clear because of a try/catch block in T-SQL. When I removed it, VS told me the error specifically. Still not sure why I got a positive return value, though.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.