码迷,mamicode.com
首页 > 数据库 > 详细

控制台实现数据库的增删改查

时间:2015-03-18 15:46:48      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

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

namespace datareader
{
    class Program
    {
        static void Main(string[] args)
        {
            string bankStr = DBHelper.connStr;
            using (SqlConnection con = new SqlConnection(bankStr))
            {
                //string sql = "insert into Grade values(@GradeName)";
                //string sql = "update Grade set GradeName=@GradeName where GradeName=‘s8‘";
                string sql = "delete from Grade where GradeName=@GradeName";
                SqlCommand cmd = new SqlCommand(sql,con);
                cmd.Parameters.AddWithValue("@GradeName",Console.ReadLine());
                con.Open();
                int n = cmd.ExecuteNonQuery();
                if (n != 1)
                {
                    Console.WriteLine("error");
                }
            }
            Console.ReadKey();
        }
    }
}

至于select:

用datareader。

控制台实现数据库的增删改查

标签:

原文地址:http://www.cnblogs.com/Penfield/p/4347213.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!