zoukankan      html  css  js  c++  java
  • linq,创建数据库,插入数据,newDB.CreateDatabase();newDB.tb2.InsertOnSubmit(stu); newDB.SubmitChanges();

    using System.Data.Linq;
    using System.Data.Linq.Mapping;

    namespace ConsoleApplication1388
    {
    class Program
    {
    static void Main(string[] args)
    {
    string sourceString = "Server=SMOOTHFU;Database=mydb2;Integrated Security=SSPI";
    CreateDB newDB = new CreateDB(sourceString);
    //创建数据库
    newDB.CreateDatabase();
    Student stu = new Student
    {
    id = 10,
    name = "ZTT"
    };

    newDB.tb2.InsertOnSubmit(stu);
    newDB.SubmitChanges();
    }
    }

    [Table(Name="SecondDB")]
    public class Student
    {
    [Column(IsPrimaryKey =true,Name="id")]
    public int id { get; set; }
    [Column(Name="name")]
    public string name { get; set; }
    }

    public class CreateDB:DataContext
    {
    public Table<Student> tb2;

    public CreateDB(string connection):base(connection)
    {

    }

    public CreateDB(System.Data.IDbConnection connection):base(connection)
    {

    }
    }

  • 相关阅读:
    Winsock 2 入门指南
    Winsock 2 入门指南
    [手游新项目历程]-40-linux环境实现C/C++程序崩溃退出时打印栈信息
    1月下旬解题
    poj1226,poj3080
    poj3666
    poj3067
    poj12月其他题解(未完)
    poj1823,3667
    poj2352
  • 原文地址:https://www.cnblogs.com/Fred1987/p/5933816.html
Copyright © 2011-2022 走看看