using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.Common; using System.Data.SqlClient; namespace WebSqlHelper { public class SqlDbHelper : DbHelper { public SqlDbHelper(string name) { db = CreateDatabase(name); } public SqlDbHelper() { db = CreateDatabase(); } public override DbParameter GetParameter() { return new SqlParameter(); } public override DataTable ExecutePager(string tbname, string fields, string where, string orderby, int pagesize, int pageindex, ref int recordcount) { if (string.IsNullOrEmpty(fields)) { fields = "*"; } DbCommand storedProcCommand = db.GetStoredProcCommand("commonPager"); storedProcCommand.Parameters.Clear(); db.AddInParameter(storedProcCommand, "tblname", DbType.String, tbname); db.AddInParameter(storedProcCommand, "strGetFields", DbType.String, fields); db.AddInParameter(storedProcCommand, "PageSize", DbType.Int16, pagesize); db.AddInParameter(storedProcCommand, "PageIndex", DbType.Int16, pageindex); db.AddInParameter(storedProcCommand, "docount", DbType.Int16, 1); db.AddInParameter(storedProcCommand, "strOrderBy", DbType.String, orderby); db.AddInParameter(storedProcCommand, "strWhere", DbType.String, where); db.AddOutParameter(storedProcCommand, "RecordCount", DbType.Int32, 4); DataSet set = db.ExecuteDataSet(storedProcCommand); recordcount = (int)db.GetParameterValue(storedProcCommand, "RecordCount"); return set.Tables[0]; } public override int GetNext(string table, string field) { return GetNext(null, table, field); } public override int GetNext(DbTransaction tran, string table, string field) { object c = GetSqlStrScalar("select max(case when ISNUMERIC(" + field + ")=1 then " + field + " else 0 end) from " + table); if (c == null || c is DBNull) return 1; return int.Parse(c.ToString()) + 1; } } }