当前位置: 首页>>代码示例>>C#>>正文


C# IDbDataAdapter.FillSchema方法代码示例

本文整理汇总了C#中IDbDataAdapter.FillSchema方法的典型用法代码示例。如果您正苦于以下问题:C# IDbDataAdapter.FillSchema方法的具体用法?C# IDbDataAdapter.FillSchema怎么用?C# IDbDataAdapter.FillSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDbDataAdapter的用法示例。


在下文中一共展示了IDbDataAdapter.FillSchema方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExtractTableParameters

        public void ExtractTableParameters(string TableName, IDbDataAdapter adapter, 
            out DatabaseCache InsertCache, 
            out DatabaseCache DeleteCache,
            out DatabaseCache UpdateCache,
            out DatabaseCache IsExistCache,
            out DataTable dt
            )
        {
            adapter.SelectCommand.CommandText = "select top 1 * from " + TableName;

            DataSet ds = new DataSet();

            dt = adapter.FillSchema(ds, SchemaType.Source)[0];

            dt.TableName = TableName;

            SqlCommandBuilder builder = new SqlCommandBuilder(adapter as SqlDataAdapter);

            builder.ConflictOption = ConflictOption.OverwriteChanges;
            //builder.SetAllValues = false;
            SqlCommand InsertCmd = builder.GetInsertCommand(true);
            builder.ConflictOption = ConflictOption.OverwriteChanges;

            InsertCache = new DatabaseCache(InsertCmd.CommandText, InsertCmd.Parameters);
            InsertCache.CurrentTable = dt;

            foreach (DataColumn c in dt.Columns)
            {
                if (c.AutoIncrement)
                {
                    InsertCache.IsHaveAutoIncrement = true;
                    InsertCache.SQL += ";Select @@IDENTITY;";
                    break;
                }
            }

            SqlCommand UpdateCmd = builder.GetUpdateCommand(true);
            UpdateCache = new DatabaseCache(UpdateCmd.CommandText, UpdateCmd.Parameters);
            UpdateCache.CurrentTable = dt;

            SqlCommand DeleteCmd = builder.GetDeleteCommand(true);
            DeleteCache = new DatabaseCache(DeleteCmd.CommandText, DeleteCmd.Parameters);
            DeleteCache.CurrentTable = dt;

            IsExistCache = new DatabaseCache(DeleteCmd.CommandText, DeleteCmd.Parameters);
            IsExistCache.CurrentTable = dt;
            IsExistCache.SQL = IsExistCache.SQL.Replace("DELETE FROM [" + TableName + "]", "Select count(1) from [" + TableName + "] with(nolock) ");
        }
开发者ID:xqgzh,项目名称:Z,代码行数:48,代码来源:SqlServer.cs

示例2: ExtractTableParameters

        public void ExtractTableParameters(string TableName, IDbDataAdapter adapter,
    out DatabaseCache InsertCache,
    out DatabaseCache DeleteCache,
    out DatabaseCache UpdateCache,
    out DatabaseCache IsExistCache,
    out DataTable dt
    )
        {
            MySqlDataAdapter adap = adapter as MySqlDataAdapter;

            adap.FillLoadOption = LoadOption.OverwriteChanges;
            adapter.SelectCommand.CommandText = "select * from " + TableName;

            DataSet ds = new DataSet();

            dt = adapter.FillSchema(ds, SchemaType.Source)[0];

            dt.TableName = TableName;

            InsertCache = new DatabaseCache(string.Empty, new IDataParameter[dt.Columns.Count]);
            DeleteCache = new DatabaseCache(string.Empty, new IDataParameter[dt.PrimaryKey.Length]);
            UpdateCache = new DatabaseCache(string.Empty, new IDataParameter[dt.Columns.Count]);
            IsExistCache = new DatabaseCache(string.Empty, new IDataParameter[dt.PrimaryKey.Length]);
            InsertCache.SQL = "insert into " + TableName + "(";
            DeleteCache.SQL = "delete from " + TableName + " where ";
            UpdateCache.SQL = "Update " + TableName + " set ";
            IsExistCache.SQL = "select count(1) from " + TableName + " where ";

            InsertCache.SQL += StringTools.JoinString(dt.Columns, string.Empty, string.Empty, ",", false);
            InsertCache.SQL += ") values(";
            InsertCache.SQL += StringTools.JoinString(dt.Columns, "?", string.Empty, ",", false);
            InsertCache.SQL += ");";

            Dictionary<string, DataColumn> PrimaryKeys = new Dictionary<string,DataColumn>();

            foreach (DataColumn c in dt.PrimaryKey)
            {
                if (c.AutoIncrement)
                    InsertCache.IsHaveAutoIncrement = true;

                PrimaryKeys.Add(c.ColumnName, c);
            }

            string s = " 1=1 ";

            foreach (DataColumn c in dt.Columns)
            {
                if (!PrimaryKeys.ContainsKey(c.ColumnName))
                {
                    UpdateCache.SQL += c.ColumnName + "=?" + c.ColumnName + ",";
                }
                else
                {
                    s += " And " + c.ColumnName + "=?" + c.ColumnName;
                }
            }

            if (UpdateCache.SQL.EndsWith(","))
                UpdateCache.SQL = UpdateCache.SQL.Remove(UpdateCache.SQL.Length - 1);

            UpdateCache.SQL += " Where ";

            DeleteCache.SQL += s;
            UpdateCache.SQL += s;
            IsExistCache.SQL += s;

            if (InsertCache.IsHaveAutoIncrement == true)
            {
                InsertCache.SQL += "select last_insert_id();";
            }

            InsertCache.Parameters = new IDataParameter[InsertCache.IsHaveAutoIncrement?dt.Columns.Count - 1:dt.Columns.Count];
            DeleteCache.Parameters = new IDataParameter[PrimaryKeys.Count];
            UpdateCache.Parameters = new IDataParameter[dt.Columns.Count];
            IsExistCache.Parameters = new IDataParameter[PrimaryKeys.Count];

            int InsertIndex = 0 , DeleteIndex = 0, UpdateIndex = 0;

            foreach (DataColumn c in dt.Columns)
            {
                IDataParameter p = adapter.SelectCommand.CreateParameter();
                p.ParameterName = "?" + c.ColumnName;
                p.SourceColumn = c.ColumnName;

                if (!c.AutoIncrement)
                {
                    InsertCache.Parameters[InsertIndex++] = p;
                }

                if (PrimaryKeys.ContainsKey(c.ColumnName))
                {
                    DeleteCache.Parameters[DeleteIndex] = p;
                    IsExistCache.Parameters[DeleteIndex] = p;
                    DeleteIndex++;
                }

                UpdateCache.Parameters[UpdateIndex] = p;
                UpdateIndex++;
            }

//.........这里部分代码省略.........
开发者ID:xqgzh,项目名称:Z,代码行数:101,代码来源:MySQL.cs


注:本文中的IDbDataAdapter.FillSchema方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。