zoukankan      html  css  js  c++  java
  • ado:SqlDataAdapter的两种不同写法,以及SqlCommand的两种不同写法

    原文发布时间为:2008-08-01 —— 来源于本人的百度文章 [由搬家工具导入]

    SqlDataAdapter:(它是自动打开连接且自动关闭的,所以可以不必显示打开关闭连接)

    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["pusConn"].ConnectionString);

           // SqlDataAdapter sda = new SqlDataAdapter("select * from authors", conn);//第一种写法
          

            SqlDataAdapter sda = new SqlDataAdapter();//第二种写法
            sda.SelectCommand = new SqlCommand("select * from authors",conn);

            DataSet ds = new DataSet();

            sda.Fill(ds,"t1");

    ----------------------------

    SqlCommand:

    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["pusConn"].ConnectionString);


    //SqlCommand cmd=new SqlCommand("delete from authors where au_id=2",conn);//第一种方法

          SqlCommand cmd=new SqlCommand();//第二种方法
            cmd.CommandText = "delete from authors where au_id=2" ;
            cmd.Connection = conn;
            

           conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();

  • 相关阅读:
    powershell:clear-item
    windows-杂笔
    powershell:Clear-EventLog
    powershell:Get-ChildItem
    powershell 杂笔
    power-shell:clear-content
    powershell:checkpoint-computer
    vim-缩进设置
    powershell:move-item
    powershell:add-content
  • 原文地址:https://www.cnblogs.com/handboy/p/7141600.html
Copyright © 2011-2022 走看看