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!

  • 相关阅读:
    Linux:文件解压与压缩
    Linux:环境变量
    Linux:Vim
    Linux:目录&文件基本操作
    Linux:文件权限
    Linux:用户&用户组操作
    Linux:Shell 常用通配符
    Linux:常用shell快捷键
    Linux:Linux 重要人物
    架构:层次化
  • 原文地址:https://www.cnblogs.com/simonhaninmelbourne/p/1496190.html
Copyright © 2011-2022 走看看