日期:2014-05-17  浏览次数:20920 次

C#数据库修改程序编译成功但数据表没改变?求大神?
C#数据库修改程序编译成功但数据表没改变

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string connString=@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True";
            using (SqlConnection conn=new SqlConnection(connString))
            {
                conn.Open();
                //SqlCommand cmd = new SqlCommand();
                //cmd.CommandText = "update [stu] set [grade]=[grade]=10 where[name]='张三丰'";
                //cmd.Connection = conn;
                SqlCommand cmd = new SqlCommand("update [stu] set [grade]="+"[grade]+10"+" where[name]='张三丰'", conn);
               // cmd.Parameters.Add(new SqlParameter("grade", [grade] + 1));
                cmd.ExecuteNonQuery();
                Console.ReadKey();
            }
 
        }
    }
}

但是我在Main()中加了一段代码就好了,但我看不懂这个代码是什么意思

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace ConsoleApplication1
{
    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);
            }

            string connString=@"Data