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!

  • 相关阅读:
    冲刺会议第七天
    冲刺会议第六天
    冲刺会议第五天
    冲刺会议第四天
    题目
    关于小程序开发者和体验者的数据请求问题
    focus、blur事件的事件委托处理(兼容各个流浏览器)
    收集的一些技术论坛博客
    ios下fixed回复框bug的解决方案
    jQuery的13个优点
  • 原文地址:https://www.cnblogs.com/simonhaninmelbourne/p/1496190.html
Copyright © 2011-2022 走看看