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

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {

            string dataDir = AppDomain.CurrentDomain.BaseDirectory;
            if (dataDir.EndsWith(@"\bin\Debug\")
                || dataDir.EndsWith(@"\bin\Release\"))
            {
                dataDir = System.IO.Directory.GetParent(dataDir).Parent.Parent.FullName;
                AppDomain.CurrentDomain.SetData("DataDirectory", dataDir);
            }
            using (SqlConnection comm = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True"))
            {
                comm.Open();
                using (SqlCommand cmd = comm.CreateCommand())
                {
                    cmd.CommandText = "insert into table(name)  valules('aba')";
                    cmd.ExecuteNonQuery();
                    Console.WriteLine("插入成功!");
                }
            }
        }
    }
}