📄 ordersdb.cs
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -