困惑几天的问题,vs2008.控制台应用程序中添加的数据库服务,不能插入数据啊。求各位高手
using System;using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
namespace 数据库
{
class Program
{
static void Main(string[] args)
{
string dataDir = AppDomain.CurrentDomain.BaseDirectory;
if (dataDir.EndsWith(@"\bin\Debug\") || dataDir.EndsWith(@"\bin\debug\"))
{
dataDir = (dataDir).Parent.Parent.FullName;
AppDomain.CurrentDomain.SetData("DateDirectory", dataDir);
}
using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLexpress;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True "))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
= "insert into Table1 (id,name) values (4,'yk')";
cmd.ExecuteNonQuery();
}
}
}
}
}