求助!复制来的代码也运行不了,求高手们指点
这段代码是我复制来的,别人都可以运行,我却运行不了,数据库我也添加好了,求助哇!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 = (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())
{
= "insert into table(name) valules('aba')";
cmd.ExecuteNonQuery();
Console.WriteLine("插入成功!");
}
}
}
}
}