日期:2014-05-18 浏览次数:20941 次
/// <summary> /// 执行查询,并返回查询所返回的结果集中第一行的第一列。忽略额外的列或行 /// </summary> /// <param name="strSQL">string</param> /// <returns>object</returns> public static object ExecuteScalarSql(string strSQL) { SqlConnection myCn = new SqlConnection(CONNECTION_STRING); SqlCommand myCmd = new SqlCommand(strSQL, myCn); try { myCn.Open(); object result = myCmd.ExecuteScalar(); return result; } catch (Exception e) { throw e; } finally { myCmd.Dispose(); myCn.Close(); } }