执行SQL存储脚本

时间:2014-05-21 04:18:08   收藏:0   阅读:388
using System.Data.SqlClient;
bubuko.com,布布扣
static void Main(string[] args)
        {
            string connString = @"Data Source=.; Initial Catalog=lh0216; User ID=sa;pwd=Founder123";
            //出了using括号objConnection类会被自动释放
            using (SqlConnection objConnection = new SqlConnection(connString))
            {
                objConnection.Open();
                Console.WriteLine("数据库连接成功。");
                using (SqlCommand objCmd = objConnection.CreateCommand())
                {
                    objCmd.CommandText = "INSERT INTO tbID(strName,strCname,iMax ) VALUES (‘aaa‘,‘测试‘,1)";
                    objCmd.ExecuteNonQuery();
                    Console.WriteLine("插入数据成功。");
                }
            }            
            Console.ReadKey();
        }
bubuko.com,布布扣

 

执行SQL存储脚本,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!