zoukankan      html  css  js  c++  java
  • SqlDataAdapter SelectCommand,InsertCommand,UpdateCommand,DeleteCommand 属性

    public static SqlDataAdapter CreateCustomerAdapter(
        SqlConnection connection)
    {
        SqlDataAdapter adapter = new SqlDataAdapter();
    
        // Create the SelectCommand.
        SqlCommand command = new SqlCommand("SELECT * FROM Customers " +
            "WHERE Country = @Country AND City = @City", connection);
    
        // Add the parameters for the SelectCommand.
        command.Parameters.Add("@Country", SqlDbType.NVarChar, 15);
        command.Parameters.Add("@City", SqlDbType.NVarChar, 15);
    
        adapter.SelectCommand = command;
    
        // Create the InsertCommand.
        command = new SqlCommand(
            "INSERT INTO Customers (CustomerID, CompanyName) " +
            "VALUES (@CustomerID, @CompanyName)", connection);
    
        // Add the parameters for the InsertCommand.
        command.Parameters.Add("@CustomerID", SqlDbType.NChar, 5, "CustomerID");
        command.Parameters.Add("@CompanyName", SqlDbType.NVarChar, 40, "CompanyName");
    
        adapter.InsertCommand = command;
    
        // Create the UpdateCommand.
        command = new SqlCommand(
            "UPDATE Customers SET CustomerID = @CustomerID, CompanyName = @CompanyName " +
            "WHERE CustomerID = @oldCustomerID", connection);
    
        // Add the parameters for the UpdateCommand.
        command.Parameters.Add("@CustomerID", SqlDbType.NChar, 5, "CustomerID");
        command.Parameters.Add("@CompanyName", SqlDbType.NVarChar, 40, "CompanyName");
        SqlParameter parameter = command.Parameters.Add(
            "@oldCustomerID", SqlDbType.NChar, 5, "CustomerID");
        parameter.SourceVersion = DataRowVersion.Original;
    
        adapter.UpdateCommand = command;
    
        // Create the DeleteCommand.
        command = new SqlCommand(
            "DELETE FROM Customers WHERE CustomerID = @CustomerID", connection);
    
        // Add the parameters for the DeleteCommand.
        parameter = command.Parameters.Add(
            "@CustomerID", SqlDbType.NChar, 5, "CustomerID");
        parameter.SourceVersion = DataRowVersion.Original;
    
        adapter.DeleteCommand = command;
    
        return adapter;
    }
  • 相关阅读:
    71、salesforce的JSON方法
    70、saleforce的Json输出
    69、schema的相关方法
    javascript时间格式转换(今天,昨天,前天)
    移动web开发都会遇到的坑(会持续更新)
    javascript实现SHA1算法
    移动端重构--重置样式
    Grunt完整打包一个项目实例
    谈谈HTML5中的history.pushSate方法,弥补ajax导致浏览器前进后退无效的问题
    关于display:inline-block布局导致错位问题分析
  • 原文地址:https://www.cnblogs.com/top5/p/1665598.html
Copyright © 2011-2022 走看看