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 tb2;

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

}

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

}
}

转载于:https://www.cnblogs.com/Fred1987/p/5933816.html

你可能感兴趣的:(linq,创建数据库,插入数据,newDB.CreateDatabase();newDB.tb2.InsertOnSubmit(stu); newDB.SubmitChanges();...)