我现在在编程中使用SQL,并且正在查询数据库。如果select语句没有返回任何行,返回什么?
scCommand = new SqlCommand("SELECT LegislationID FROM Legislation WHERE Number = @ECERegulation", sconConnection);
scCommand.Parameters.Add("@ECERegulation", SqlDbType.NVarChar);
scCommand.Parameters["@ECERegulation"].Value = strECERegulation;
return (int)scCommand.ExecuteScalar();
我的问题是,如果我的参数不匹配我查询的表中的任何内容,会返回什么?我需要有一个if语句来处理不匹配的ECERegulation。它会返回null吗?或者它会返回零立法ID?任何帮助,将不胜感激。
什么阻止你试图找出? – 2011-06-01 18:21:16
或阅读MSDN的ExecuteScalar看看它是否告诉你? – Nik 2011-06-01 18:22:45