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


C# SqlDataAdapter.FillSchema方法代码示例

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


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

示例1: connectToServer

        private void connectToServer()
        {
            SqlConnection conn = Connection.getConnection();
            
            try
            {
                conn.Open();

                tradeDataAdapter = new SqlDataAdapter("SELECT * FROM tb_trade", conn);
                saleDataAdapter = new SqlDataAdapter("SELECT * FROM tb_sale", conn);
                vipDataAdapter = new SqlDataAdapter("SELECT * FROM tb_vip", conn);

                //先获取所有商品信息填充到dataset去
                SqlCommand cmd = new SqlCommand("SELECT * FROM view_commodity_cashier", conn);
                SqlDataReader reader = cmd.ExecuteReader();

                DataTable tb_commodity = new DataTable("commodity");
                tb_commodity.Load(reader);

                dataset.Tables.Add(tb_commodity);
                reader.Close();

                //获取tb_trade表
                tradeDataAdapter.Fill(dataset, "trade");

                //获取tb_sale表
                saleDataAdapter.Fill(dataset, "sale");

                //获取tb_vip表
                vipDataAdapter.Fill(dataset, "vip");

                StringBuilder builder = new StringBuilder();
                //获取当前的购物表模式
                //拼接select语句
                builder.Append("SELECT ");
                builder.Append("tb_commodity.s_code 条形码, ");
                builder.Append("tb_commodity.s_name 商品名, ");
                builder.Append("tb_commodity.s_price 商品单价, ");
                builder.Append("tb_sale.sale_count 数量, ");
                builder.Append("tb_sale.sale_amount 合计  ");
                builder.Append("FROM tb_commodity,tb_sale");

                SqlDataAdapter shoplistAdapter = new SqlDataAdapter(builder.ToString(), conn);
                shoplistAdapter.FillSchema(dt, SchemaType.Mapped);

                SqlCommandBuilder cmdBuilder1 = new SqlCommandBuilder(tradeDataAdapter);
                SqlCommandBuilder cmdBuilder2 = new SqlCommandBuilder(saleDataAdapter);
                SqlCommandBuilder cmdBuilder3 = new SqlCommandBuilder(vipDataAdapter);
                SqlCommandBuilder cmdBuilder4 = new SqlCommandBuilder(shoplistAdapter);

            }
            catch (Exception e)
            {
                MessageBox.Show("连接至服务器失败,请检查连接!错误:"+e.ToString(), "错误");
            }
            finally
            {
                conn.Close();
            }
        }
开发者ID:microstudent,项目名称:DataBaseDemo,代码行数:60,代码来源:PosManager.cs

示例2: getAllCountries

    /// <summary>
    /// Gets all customers in the database
    /// </summary>
    /// <returns>DataTable with all customers in database</returns>
    private DataTable getAllCountries(string startsWith)
    {
        // Create and instantiate connection
        using (customerManagementConnection = new SqlConnection())
        {
            // Initialize connection string from web.config
            customerManagementConnection.ConnectionString =
                ConfigurationManager.ConnectionStrings[
                "CustomerManagementConnectionString"].ConnectionString;

            // Open connection
            customerManagementConnection.Open();

            // Declare and instantiate data adapter
            using (SqlDataAdapter customerManagementDataAdapter = new SqlDataAdapter())
            {
                // Declare and instantiate command objects
                SqlCommand selectCommand = new SqlCommand(
                    "SELECT * FROM Countries WHERE Name LIKE '" + startsWith + "%'", customerManagementConnection);
                // Assign command objects
                customerManagementDataAdapter.SelectCommand = selectCommand;

                // Declare and instantiate DataTable
                countriesDataTable = new DataTable("Countries");
                // Apply the full schema from the data source
                customerManagementDataAdapter.FillSchema(countriesDataTable, SchemaType.Source);
                customerManagementDataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
                customerManagementDataAdapter.MissingMappingAction = MissingMappingAction.Passthrough;
                // Populate Customers DataTable
                customerManagementDataAdapter.Fill(countriesDataTable);
            }
        }

        return countriesDataTable;
    }
开发者ID:developer145,项目名称:AspNet,代码行数:39,代码来源:Customers.cs

示例3: FillDataSet

        static DataSet FillDataSet(string SQLquery)
        {
            string sConnectionString = common.getConnectionString();

            SqlConnection objConn
                = new SqlConnection(sConnectionString);
            objConn.Open();

            SqlDataAdapter daAuthors
                = new SqlDataAdapter(SQLquery, objConn);
            DataSet ds = new DataSet("Area");
            daAuthors.FillSchema(ds, SchemaType.Source, "AreaTable");
            daAuthors.Fill(ds, "AreaTable");

            /*DataTable tblAuthors;
            tblAuthors = ds.Tables["AreaTable"];

            foreach (DataRow drCurrent in tblAuthors.Rows)
            {
                Console.WriteLine("{0} {1}",
                    drCurrent["ID"].ToString(),
                    drCurrent["Name"].ToString());
            }
            Console.ReadLine();*/
            return ds;
        }
开发者ID:npenkrat,项目名称:las,代码行数:26,代码来源:List.aspx.cs

示例4: OrderDetailList

        public static List<OrderDetail> OrderDetailList(int OrderID)
        {
            //Copied code from Nwind.cs VVVV
            List<OrderDetail> OrdDetList = new List<OrderDetail>();

            sqlCon = new SqlConnection(connectionString);
            sqlCon.Open();

            SqlDataAdapter da;
            DataTable dt = new DataTable();
            SqlCommand cmd = new SqlCommand(PROC_ORD_DETAILS, sqlCon);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@OrderID", OrderID));

            da = new SqlDataAdapter(cmd);
            da.FillSchema(dt, SchemaType.Source);
            da.Fill(dt);

            sqlCon.Close();
            //Copied code^^^^
            foreach (DataRow row in dt.Rows)
            {
                //int OrderID = (int)row["OrderID"];
                //string ProductName = (string)row["ProductName"];
                int ProductID = (int)row["ProductID"];
                decimal UnitPrice = (decimal)row["UnitPrice"];
                short Quantity = (short)row["Quantity"];
                float Discount = (float)row["Discount"];

                OrderDetail OrD = new OrderDetail(OrderID,ProductID,UnitPrice,Quantity,Discount);
                OrdDetList.Add(OrD);
            }
      /*put code here */
            return OrdDetList;
        }
开发者ID:larryslack,项目名称:OrderingProject,代码行数:35,代码来源:NwindOrderDetails.cs

示例5: Consultar

        public DataTable Consultar(string query)
        {
            DataTable dt = new DataTable();

            cmd = new SqlCommand();
            cmd.CommandType = System.Data.CommandType.Text;
            cmd.CommandText = query;
            cmd.CommandTimeout = 10;

            try
            {
                cmd.Connection = getConnection();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.FillSchema(dt, SchemaType.Source);
                da.Fill(dt);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                cnn.Close();
            }

            return dt;
        }
开发者ID:ulplab,项目名称:G2_C2_2015_LABIII,代码行数:27,代码来源:clsDBManager.cs

示例6: getAllStudents

 public DataTable getAllStudents()
 {
     SqlConnection conn = null;
     DataTable table = null;
     SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
     using (conn = new SqlConnection(connStr))
     {
         try
         {
             conn.Open();
             String query = "SelectProcedure1";
             SqlCommand com = new SqlCommand(query, conn);
             com.CommandType = CommandType.StoredProcedure;
             sqlDataAdapter.SelectCommand = com;
             DataSet dataSet = new DataSet();
             sqlDataAdapter.FillSchema(dataSet, SchemaType.Source, "Registration");
             sqlDataAdapter.Fill(dataSet, "Registration");
             table = dataSet.Tables["Registration"];
             return table;
         }
         catch (SqlException ex)
         {
           Console.WriteLine(ex.ToString(), "Sql Exception");
             return null;
         }
         finally
         {
             if (conn != null)
             {
                 conn.Close();
             }
         }
     }
 }
开发者ID:akila91,项目名称:Assignnment,代码行数:34,代码来源:Dbconnection.cs

示例7: BuildCustomerTable

        /// <summary>
        ///    /************************************************************************************************
        ///    Populate CUSTOMER table
        ///    By Wesley D. Brown
        ///    Date 11/24/2007
        ///    Mod
        ///    **Description**
        ///    Functions:
        ///    **End Discription**
        ///    **Change Log**
        ///    **End Change Log**
        ///    ************************************************************************************************/
        /// </summary>
        /// <returns></returns>
        public void BuildCustomerTable()
        {
            var currdate = new DateTime();
            var dt = new DataTable();

            var sqlConnect = new SqlConnection {ConnectionString = Sqlconn};
            sqlConnect.Open();

            var dc = new SqlCommand("select top 0 * from dbo.CUSTOMER", sqlConnect) {CommandType = CommandType.Text};
            var da = new SqlDataAdapter(dc);
            da.FillSchema(dt, SchemaType.Mapped);

            sqlConnect.Close();
            sqlConnect.Dispose();

            var bulkCopy = new SqlBulkCopy(Sqlconn,SqlBulkCopyOptions.TableLock) {DestinationTableName = "dbo.CUSTOMER", BatchSize = 10000};

            int i = NumWh;
            int tid = (NumWh*10*3000) + 1;

            while (i < MaxNumWh + 1)
            {
                for (int id = 1; id < 11; id++)
                {
                    for (int cid = 1; cid < 3001; cid++)
                    {
                        DataRow dr  = dt.NewRow();
                        dr["C_ID"] = "C_W" + i + "_D" + id + "_" + cid;
                        dr["C_D_ID"] = "D_W" + i + "_" + id;
                        dr["C_W_ID"] = "W_" + i;
                        dr["C_FIRST"] = RandomString(5, 16);
                        dr["C_MIDDLE"] = "oe";
                        dr["C_LAST"] = RandomString(8, 16);
                        dr["C_STREET_1"] = RandomString(10, 20);
                        dr["C_STREET_2"] = RandomString(10, 20);
                        dr["C_CITY"] = RandomString(10, 20);
                        dr["C_STATE"] = RandomString(2, 2);
                        dr["C_ZIP"] = RandZip();
                        dr["C_PHONE"] = RandomString(12, 12);
                        dr["C_SINCE"] = currdate.ToLongTimeString();
                        dr["C_CREDIT"] = "GC";
                        dr["C_CREDIT_LIM"] = 5000;
                        dr["C_DISCOUNT"] = .5;
                        dr["C_BALANCE"] = -10.00;
                        dr["C_YTD_PAYMENT"] = 10.00;
                        dr["C_PAYMENT_CNT"] = 1;
                        dr["C_DELIVERY_CNT"] = 0;
                        dr["C_DATA"] = RandomString(300, 500);
                        dr["SEQ_ID"] = tid;
                        dt.Rows.Add(dr);
                    }
                }
                bulkCopy.WriteToServer(dt);
                dt.Clear();

                i++;
            }
            return;
        }
开发者ID:SQLServerIO,项目名称:TPCCBench,代码行数:73,代码来源:TPCCGenData.cs

示例8: GetAndFillDataSet

        protected DataSet GetAndFillDataSet(SqlDataAdapter adapter)
        {
            DataSet dts = new DataSet(NewTableName);
            adapter.FillSchema(dts, SchemaType.Source, NewTableName);
            adapter.Fill(dts);

            return dts;
        }
开发者ID:GiveCampUK,项目名称:PPT_2,代码行数:8,代码来源:AbstractTableMigrationService.cs

示例9: backgroundWorker1_DoWork

 private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
 {
     dsPubs.Clear();
     gros = new SqlDataAdapter("SELECT [Gross] FROM Payments Where [ID] LIKE '%" + id[i].id.ToString() + "%' AND [Year] LIKE '%" + DateTime.Now.Year.ToString() + "%'", Form1.Conn);
     dsPubs = new DataSet("Pubs");
     gros.FillSchema(dsPubs, SchemaType.Source, "Payments");
     gros.Fill(dsPubs, "Payments");
     dsPubs.Dispose();
 }
开发者ID:applyACS,项目名称:LTDesktop,代码行数:9,代码来源:pay_detail.cs

示例10: ExecuteDataTable

 /// <summary>
 /// 执行sql返回dataable
 /// </summary>
 /// <param name="sql"></param>
 /// <returns></returns>
 private DataTable ExecuteDataTable(string sql)
 {
     DataSet ds = new DataSet();
     try
     {
         switch (sqltype)
         {
             case 1:
                 using (SqlConnection conn = new SqlConnection(cononstr))
                 {
                     conn.Open();
                     using (SqlCommand cmd = conn.CreateCommand())
                     {
                         cmd.CommandText = sql;
                         using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
                         {
                             adapter.FillSchema(ds, SchemaType.Source);
                             adapter.Fill(ds);
                         }
                     }
                 }
                 break;
             case 2:
                 using (MySqlConnection conn = new MySqlConnection(cononstr))
                 {
                     conn.Open();
                     using (MySqlCommand cmd = conn.CreateCommand())
                     {
                         cmd.CommandText = sql;
                         using (MySqlDataAdapter adapter = new MySqlDataAdapter(cmd))
                         {
                             adapter.FillSchema(ds, SchemaType.Source);
                             adapter.Fill(ds);
                         }
                     }
                 }
                 break;
             default: break;
         }
         return ds.Tables[0];
     }
     catch (Exception ex)
     {
         this.Dispatcher.Invoke(delegate
         {
             tbModel.Text = "连接字符串填写错误,请检查。\n错误信息:" + ex.Message + "\n" + ex.ToString();
             tbDAL.Text = ex.Message + "\n" + ex.ToString();
         });
         ConnectSqlFailed();
         return null;
     }
     finally
     {
         this.Dispatcher.Invoke(delegate { btnConnect.IsEnabled = true; tbConnStr.IsEnabled = true; });
     }
 }
开发者ID:MrNener,项目名称:CodeBuilder,代码行数:61,代码来源:MainWindow.xaml.cs

示例11: log_Load

 private void log_Load(object sender, EventArgs e)
 {
     SqlDataAdapter daAuthors = new SqlDataAdapter("Select * From log", Form1.Conn);
     DataSet dsPubs = new DataSet("Pubs");
     //dsPubs.Tables["LTD"].Columns.Add(no);
     daAuthors.FillSchema(dsPubs, SchemaType.Source, "log");
     daAuthors.Fill(dsPubs, "log");
     //dsPubs.Tables["LTD"].Columns.Add(no);
     bindingSource1.DataSource = dsPubs.Tables["log"];
     dgv_log.DataSource = bindingSource1;
 }
开发者ID:applyACS,项目名称:LTDesktop,代码行数:11,代码来源:log.cs

示例12: GetTableMetadata

 public Table GetTableMetadata(string tableName)
 {
     string selectCmdText = string.Format("SELECT * FROM [{0}]", tableName);
     ;
     SqlCommand command = new SqlCommand(selectCmdText, conn);
     SqlDataAdapter ad = new SqlDataAdapter(command);
     System.Data.DataSet ds = new DataSet();
     ad.FillSchema(ds, SchemaType.Mapped, tableName);
     Table table = new Table(ds.Tables[0]);
     return table;
 }
开发者ID:yaozd,项目名称:DapperTemplateMultiDatabaseForMySql,代码行数:11,代码来源:SqlServerSchema.cs

示例13: cargarTabla

        private void cargarTabla(string tabla)
        {
            SqlConnection conexion = conectarBD();

            conexion.Open();
            SqlDataAdapter dataAdapter = new SqlDataAdapter(String.Format("SELECT * FROM {0}", tabla), conexion);
            dataAdapter.FillSchema(Datos, SchemaType.Source, tabla);
            dataAdapter.Fill(Datos, tabla);
            dataAdapters.Add(tabla, dataAdapter);
            conexion.Close();
        }
开发者ID:huang-lu,项目名称:PoEAA,代码行数:11,代码来源:Gateway.cs

示例14: Products

        private DataTable Products()
        {
            var connection = ConfigurationManager.ConnectionStrings["NorthwindEntities"].ConnectionString;
            using (var dataAdapter = new SqlDataAdapter("SELECT * from Products", connection))
            {
                var dataTable = new DataTable();

                dataAdapter.Fill(dataTable);
                dataAdapter.FillSchema(dataTable, SchemaType.Mapped);
                return dataTable;
            }
        }
开发者ID:turtlechalk,项目名称:ui-for-aspnet-mvc-examples,代码行数:12,代码来源:HomeController.cs

示例15: MyDBTable

        public MyDBTable(SqlConnection conn, string sql)
        {
            this._conn = conn;
            if (_conn.State != ConnectionState.Open) _conn.Open();
            this._tableName = "_tft_";// tableName;
            //string sql = "select * from [" + _tableName + "] ";
            this._adapter = new SqlDataAdapter(sql, _conn);

            _adapter.FillSchema(_ds, SchemaType.Source, _tableName);
            _adapter.Fill(_ds, _tableName);
            _dt = _ds.Tables[_tableName];
        
        }
开发者ID:kissmettprj,项目名称:lnv.post,代码行数:13,代码来源:MyDBTable.cs


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