zoukankan      html  css  js  c++  java
  • c# ExecuteNonQuery方法

    Inset,Update,Delelte的数据修改操作也不返回任何数据,我们对这些命令感兴趣的是修改操作影响的行数,可以用ExecuteNonQuery()方法

    using System.Data;
    using System.Data.SqlClient;
    namespace ExecuteNonQueryExample
    {
        
    class Program
        {
            
    static void Main(string[] args)
            {
                SqlConnection thisConnection 
    = new SqlConnection(
               
    @"Data Source=scott;Initial Catalog=northwind;Persist Security Info=True;User ID=sa;Password=sa123");
                thisConnection.Open();

                SqlCommand thisCommand 
    = thisConnection.CreateCommand();
                thisCommand.CommandText 
    = "update products set unitPrice=unitprice*1.05 where SupplierId=12";

                
    //Inset,Update,Delelte的数据修改操作也不返回任何数据,我们对这些命令感兴趣的是修改操作影响的行数,可以用ExecuteNonQuery()方法
                int rowsAffected = thisCommand.ExecuteNonQuery();
                Console.WriteLine(
    "Rows Updated={0}", rowsAffected);
                thisConnection.Close();

                Console.ReadLine();
            }
        }
    }

     结果:

           Rows Updated=5

  • 相关阅读:
    单例模式
    建造者模式
    工厂方法模式
    原型模式
    适配器模式
    桥接模式
    装饰模式
    组合模式
    多线程的学习与GDI的学习
    我们复习.Net的这些日子里
  • 原文地址:https://www.cnblogs.com/scottckt/p/1270231.html
Copyright © 2011-2022 走看看