日期:2014-05-18 浏览次数:20523 次
/// <summary> /// 返回一个数据 /// </summary> /// <param name="strSql"></param> /// <returns></returns> public string ExecuteScalar(string strSql) { string tmp = ""; SqlConnection conn = new SqlConnection(ConnectionString); try { conn.Open(); SqlCommand cmd = new SqlCommand(strSql, conn); tmp = cmd.ExecuteScalar().ToString(); conn.Close(); } catch { conn.Close(); } finally { conn.Close(); conn.Dispose();//释放连接 } return tmp; } //调用 string sql3 = "select count(*) from fabiaoneirong"; int count=Convert.Int32(ExecuteScalar(sql3));//行总数
------解决方案--------------------
int count=Convert.ToInt32(ExecuteScalar(sql3));//行总数
也可用int.Parse转换成整型,需注意下异常处理。
------解决方案--------------------
ds.Tables["aa"].Rows.Count