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!

  • 相关阅读:
    NSLayoutAttribute
    iOS自动布局
    UIView animateWithDuration 使用详解
    objective-c calendar 日历(2)
    objective-c calendar 日期
    ElasticSearch学习笔记
    PAT007 六度空间
    PAT006 Tree Traversals Again
    PAT005 Path in a Heap
    PAT004 Root of AVL Tree
  • 原文地址:https://www.cnblogs.com/simonhaninmelbourne/p/1496190.html
Copyright © 2011-2022 走看看