zoukankan      html  css  js  c++  java
  • Linq to SQL 根据自己需要更改数据源

    如何动态改变Linq to SQL的数据源?

    1. DBLinqDataContext 是UI自动建立的类, MyDataContext是我的子类, myConnectionString from web.config

     public class MyDataContext : DBLinqDataContext

        {
            private static class ConnectionParams
            {
                public static String ConnectionString
                {
                    get
                    {
                        return ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
                    }
                }
            }
            public MyDataContext(): base(ConnectionParams.ConnectionString)
            {
            }

        }

     2. how to use :

    using (MyDataContext ctx = new MyDataContext())
                { //change according to your situation
                   /* Table<Customer> CustomerDataTable;
                    CustomerDataTable= ctx.Customers;
                    DataLinq.Customer dd = ctx.Customers.First();

                    gvCustomer.DataSource = (from tbl in CustomerDataTable
                                             select new
                                             {
                                                 tbl.CustomerID,
                                                 tbl.CompanyName,
                                                 tbl.ContactName,
                                                 tbl.ContactTitle,
                                                 tbl.Address
                                             });
                    gvCustomer.DataBind();*/

                }

    Give it a try!

  • 相关阅读:
    vue 使用 <iframe> 嵌入网页 地址实现动态配置
    vue 视频播放 vue-video-player
    vue 实现自定义序号, 并且翻页序号累加。
    关于 vue 使用 Handsontable 表格数据导出
    node.js Stream流的使用
    手把手教如何搭建node+egg项目 引入Sequelize
    实现 通过数据库里一个字段值相等 则把 他合为一条数据
    最近在项目中碰到把对象数组转为键值对,
    js 的数组怎么push一个对象. Js数组的操作push,pop,shift,unshift JavaScrip
    for循环
  • 原文地址:https://www.cnblogs.com/simonhaninmelbourne/p/1496190.html
Copyright © 2011-2022 走看看