将4年级的学生成绩全部修改为100分,。修改前的学生信息表如图所示:

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudentUpdate
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string connectionString =                                                      //数据库连接字串
         "Data Source=.\\SQLExpress;Database=aq;Trusted_Connection=true;";//aq是数据库名
            SqlConnection connection = new SqlConnection(connectionString);//创建数据库连接实例
            connection.Open();                                                          //打开数据库连接
            Console.WriteLine("数据库student连接成功!");
            Console.ReadKey();
            //)将4年级的学生成绩改为100分
            SqlCommand cmd = new SqlCommand();                        //创建数据查询类实例
            cmd.Connection = connection;
            cmd.CommandText = "UPDATE staq_info SET result=100 WHERE grade=4";//staq_info是ST下的表格
            int count = cmd.ExecuteNonQuery();
            if (count > 0) Console.WriteLine("修改student_info表中学生信息成功!");
            cmd.Dispose();
            connection.Close();                                        //关闭数据库连接
            Console.ReadKey();
        }
    }
}
本实例代码主要利用SQL语句实现了数据表记录的修改。首先通过SqlConnection对象对数据库进行连接,然后通过SqlCommand对象执行修改数据表的SQL语句。
运行C#代码:

然后在SQL Server Management Studio Management Studio 查看修改后的结果(先刷新):




















