Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

C# SqlCommand ExecuteNonQuery value

Avatar of jkavx
jkavx asked on
C#
1 Comment1 Solution973 ViewsLast Modified:
I'm confused about the value returned by the SqlCommand ExecuteNonQuery method.  I'm doing something like this:
    string sSql = "CREATE TABLE #TMP_X (COLA nvarchar(255), COLB nvarchar(max))";
    SqlCommand cmd = new SqlCommand(sSql, SqlConn);
    int iRowCt = cmd.ExecuteNonQuery();

The value of iRowCt is -1, but the table is created and records can be inserted to it.  If I execute the same command directly in isql or in a stored proc, @@ROWCOUNT = 0.  What exactly is ExecuteNonQuery returning, and is the -1 return value that I'm getting indicative of any problem?