陈斌彬的技术博客

Stay foolish,stay hungry

利用dbml向sql插入数据

img

img

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            bb_tblAsset table = new bb_tblAsset
            {
                id = "4",//如果数据库有设置主键,同时标识自增量,则id这句话可以省略。
                BaseStation = "101",
                SiteX = "101"

            };
            DataClasses1DataContext ctx = new DataClasses1DataContext();
            ctx.bb_tblAsset.InsertOnSubmit(table);
            ctx.SubmitChanges();

        }
    }

或者是

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            bb_tblAsset table = new bb_tblAsset();
            table.BaseStation = "10001";
            table.SiteX = "1001";
            table.remark = "d0d";

            DataClasses1DataContext ctx = new DataClasses1DataContext();
            ctx.bb_tblAsset.InsertOnSubmit(table);
            ctx.SubmitChanges();


        }
    }

}

Resource Reference