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


C# System.Data.SqlClient.SqlDataAdapter.FillSchema方法代码示例

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


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

示例1: Update_1_Row

        /// <summary>
        /// Update one row
        /// </summary>
        /// <param name="pFileString">File String</param>
        /// <param name="pUpdateSQL">Update SQL Statement</param>
        /// <param name="pCommand">Command</param>
        /// <returns>bool</returns>
        public static bool Update_1_Row(string pFileString, string pSelectSQL, string pKeyString, System.Data.Common.DbDataReader pDataReader)
        {
            bool result = false;

            System.Data.SqlClient.SqlConnection Conn = null;
            System.Data.OleDb.OleDbConnection ConnOle = null;
            System.Data.SqlClient.SqlDataAdapter Adapter = null;
            System.Data.OleDb.OleDbDataAdapter AdapterOle = null;
            System.Data.SqlClient.SqlCommandBuilder builderSQL = null;
            System.Data.OleDb.OleDbCommandBuilder builderOLE = null;
            System.Data.SqlClient.SqlCommand cmdSqL = null;
            System.Data.Common.DbCommand cmdOle = null;

            DataSet dataSet = new DataSet();
            DataTable Temp = new DataTable();

            string ConnectionString = DBReadExecute.ParseConnectionString(pFileString);
            StringBuilder UpdateSQL = new StringBuilder();

            try
            {
            Type SQLServerType = Type.GetType("Epi.Data.SqlServer.SqlDBFactory, Epi.Data.SqlServer");
            if (DBReadExecute.DataSource.GetType().AssemblyQualifiedName == SQLServerType.AssemblyQualifiedName)
            {

                //case DBReadExecute.enumDataSouce.SQLServer:
                Conn = new System.Data.SqlClient.SqlConnection(ConnectionString);
                Adapter = new System.Data.SqlClient.SqlDataAdapter(pSelectSQL, Conn);
                //Adapter.FillSchema(dataSet, SchemaType.Source, pDestinationTableName);
                Adapter.FillSchema(dataSet, SchemaType.Source);
                builderSQL = new System.Data.SqlClient.SqlCommandBuilder(Adapter);
                Conn.Open();

                cmdSqL = Conn.CreateCommand();
                cmdSqL = builderSQL.GetInsertCommand();
                cmdSqL.CommandTimeout = 1500;

                UpdateSQL.Append("Update ");
                UpdateSQL.Append(pSelectSQL.Replace("Select * From ", ""));
                UpdateSQL.Append(" Set ");
                foreach (System.Data.SqlClient.SqlParameter param in cmdSqL.Parameters)
                {
                    //string FieldName = param.ParameterName.TrimStart(new char[] { '@' });
                    string FieldName = param.SourceColumn;
                    try
                    {

                        StringBuilder TUpdateSQL = new StringBuilder();

                        if (pDataReader[FieldName] != DBNull.Value && !string.IsNullOrEmpty(pDataReader[FieldName].ToString()))
                        {
                            TUpdateSQL.Append("[");
                            TUpdateSQL.Append(FieldName);
                            TUpdateSQL.Append("]=");

                            switch (pDataReader[FieldName].GetType().ToString())
                            {
                                case "System.Boolean":
                                    if (Convert.ToBoolean(pDataReader[FieldName]) == false)
                                    {
                                        TUpdateSQL.Append("0");
                                    }
                                    else
                                    {
                                        TUpdateSQL.Append("1");
                                    }
                                    break;
                                case "System.Int32":
                                case "System.Decimal":
                                case "System.Double":
                                case "System.Single":
                                case "System.Byte":
                                    TUpdateSQL.Append(pDataReader[FieldName].ToString().Replace("'", "''"));
                                    break;
                                default:
                                    TUpdateSQL.Append("'");
                                    TUpdateSQL.Append(pDataReader[FieldName].ToString().Replace("'", "''"));
                                    TUpdateSQL.Append("'");
                                    break;
                            }
                            TUpdateSQL.Append(",");
                        }

                        UpdateSQL.Append(TUpdateSQL);
                    }
                    catch (Exception ex)
                    {
                        // do nothing
                    }

                }
                UpdateSQL.Length = UpdateSQL.Length - 1;
                UpdateSQL.Append(" Where ");
//.........这里部分代码省略.........
开发者ID:NALSS,项目名称:epiinfo-82474,代码行数:101,代码来源:Rule_Merge.cs


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