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

Recommended Answers

All 3 Replies

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;

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.