• 00
  • :
  • 00
  • :
  • 00

GZDBHelper

NuGet:GZDBHelper

 

初始化:

 public class APIBase : ApiController
    {
        protected GZDBHelper.IDatabase db;
        public APIBase()
        {
            string sql = GZDBHelper.ConnectionStrings.BuildMSSQLConnectionString("local", "WDKB", "sa", "test");
            db = GZDBHelper.DatabaseFactory.CreateDatabase(sql, GZDBHelper.ConnectionStrings.ProviderNames.ProviderNameForMSSql, null);
        }
    }

命令参数类:

 public class SqlParameterProvider : DbParameterBase
    {

        //DbParameter GenerateParmeter(string parameterName, object value);

        //DbParameter GenerateParmeter(string parameterName, SqlDbType dbType);

        //DbParameter GenerateParmeter(string parameterName, SqlDbType dbType, int size);

        //DbParameter GenerateParmeter(string parameterName, SqlDbType dbType, int size, string sourceColumn);
        //protected abstract DbParameter GenerateParmeter(string parameterName, SqlDbType dbType, int size, string sourceColumn, ParameterDirection direction);

        //DbParameter GenerateParmeter(string parameterName, SqlDbType dbType, int size, ParameterDirection direction, bool isNullable, byte precision, byte scale, string sourceColumn, DataRowVersion sourceVersion, object value);

        //DbParameter SqlParameter(string parameterName, SqlDbType dbType, int size, ParameterDirection direction, byte precision, byte scale, string sourceColumn, DataRowVersion sourceVersion, bool sourceColumnNullMapping, object value, string xmlSchemaCollectionDatabase, string xmlSchemaCollectionOwningSchema, string xmlSchemaCollectionName);
        public void AddParameter(string parameterName, object value)
        {
            SqlParameter parm = new SqlParameter(parameterName, value);
            AddParameter(parm);
        }
        public void AddParameter(string parameterName, SqlDbType dbType, object value)
        {
            SqlParameter parm = new SqlParameter(parameterName, dbType);
            parm.Value = value;
            AddParameter(parm);
        }

        public void AddParameter(string parameterName, SqlDbType dbType, int size, object value)
        {
            SqlParameter parm = new SqlParameter(parameterName, dbType, size);
            parm.Value = value;
            AddParameter(parm);
        }
        public void AddParameter(string parameterName, SqlDbType dbType, int size, object value, ParameterDirection direction)
        {
            SqlParameter parm = new SqlParameter(parameterName, dbType, size);
            parm.Value = value;
            parm.Direction = direction;
            AddParameter(parm);
        }
        public void AddParameter(string parameterName, SqlDbType dbType, int size, object value, string sourceColumn)
        {
            SqlParameter parm = new SqlParameter(parameterName, dbType, size, sourceColumn);
            parm.Value = value;
            AddParameter(parm);
        }
    }

 使用例子:

 

详细文档参考:http://www.yesdotnet.com/archive/gzhelper/1614552868.html

 

posted @ 2017-09-11 15:48  Garson_Zhang  阅读(293)  评论(0编辑  收藏  举报