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

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。

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。