SqlConnection con = new SqlConnection(cnstr);
SqlCommand cmd = new SqlCommand(sqlStmt, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
try {
cmd.Connection.Open();
rows = cmd.ExecuteNonQuery();
if (rows == -1) {
Response.Write("No Rows returned from query");
Response.End();
}
Message + "\n" + "LineNumber: " + ex.Errors[i].LineNumber + "\n" + "Source: " + ex.Errors[i].Source + "\n" + "Procedure: " + ex.Errors[i].Procedure + "\n"); } Response.Write(errorMessages.ToString()); }

Suthish NairRank #92 · 22.8K reputationPosted Oct 21, 2010, 9:50 PM EDT
IF EXISTS (SELECT * from Orders where orderID = 500) SELECT * from Orders where orderID = 500 ELSE SELECT 0Suthish NairRank #92 · 22.8K reputationPosted Oct 25, 2010, 12:06 AM EDT
Lyle Griess13 reputationPosted Oct 25, 2010, 7:16 AM EDT
Sam HobbsRank #108 · 20.5K reputationPosted Oct 25, 2010, 7:36 PM EDT
Lyle Griess13 reputationPosted Oct 26, 2010, 9:01 AM EDT
cmd.Connection.Open();
rows = cmd.ExecuteNonQuery();
if (rows == -1) {
Response.Write("No Rows returned from query");
Response.End();
and viewing the doc on this command does not show how to do it.
the sqlStmt that gets passed is a dynamic select statement.
rows passed back from this is the "rows affected" and is always -1 for select statements.
Sam HobbsRank #108 · 20.5K reputationPosted Oct 26, 2010, 12:51 PM EDT
Look at the documentation again; it is extremely clear why the return value from ExecuteNonQuery is "always -1 for select statements". If you already knew that then posting the sample code was useless; you should have asked how to do what you need to do.
Lyle Griess13 reputationPosted Oct 26, 2010, 12:54 PM EDT
Sam HobbsRank #108 · 20.5K reputationPosted Oct 26, 2010, 2:07 PM EDT
When I ask a question, I am happy to get help locating the documentation or article that has the answer.
I think the one that is quibbling is the one that refuses to do what they are asked to do before requesting assistance.