ordersdb.cs

来自「Professional ASP.NET source code」· CS 代码 · 共 58 行

CS
58
字号
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections;

namespace IBuyAdventure
{



   public class OrdersDB
   {
      string m_ConnectionString;

      public OrdersDB( string dsn ) {
         m_ConnectionString = dsn;
      }
      public DataSet GetOrdersForCustomer(string customerName) {

          SqlConnection sqlConnection = new SqlConnection( m_ConnectionString);
          SqlDataAdapter sqlAdapter1 = new SqlDataAdapter("SELECT * FROM Orders WHERE CustomerName='"+customerName+"'", sqlConnection);

          DataSet products = new DataSet();
          sqlAdapter1.Fill(products, "products");

          return products;
      }   
   
      public void AddNewOrder(string customerName, string ordered, double orderValue) {

          String insertStatement = "INSERT INTO Orders(CustomerName, Ordered, TotalValue) values ('" + customerName + "', '" + ordered + "' , '" + orderValue + "')";

          SqlConnection sqlConnection = new SqlConnection( m_ConnectionString);
          SqlCommand myCommand = new SqlCommand(insertStatement, sqlConnection);

          myCommand.Connection.Open();
          myCommand.ExecuteNonQuery();
          myCommand.Connection.Close();
      }

      public void DeleteOrdersForCustomer(string customerName) {
      
          String updateStatement = "Delete Orders where customerName ='" + customerName + "'";

          SqlConnection sqlConnection = new SqlConnection( m_ConnectionString);
          SqlCommand myCommand = new SqlCommand(updateStatement, sqlConnection);

          myCommand.Connection.Open();
          myCommand.ExecuteNonQuery();
          myCommand.Connection.Close();
      }

   }

}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?