cmd.CommandText = sql;
//配参数
cmd.Parameters.Add(new SqlParameter("@productName", dal.ProductName));
cmd.Parameters.Add(new SqlParameter("@unitprice", dal.Unitprice));
cmd.Parameters.Add(new SqlParameter("@special", dal.Special));
cmd.Parameters.Add(new SqlParameter("@categoryId", dal.CategoryId));
cmd.Parameters.Add(new SqlParameter("@productId", dal.ProductId));
con.Open();
try
{
cmd.ExecuteNonQuery();
}
finally
{
con.Close();
}
}
public static void Delete(int productId)
{
string sql = "delete Product where productId=@productId";
SqlConnection con = new DBConnection().Con;
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = sql;
//配参数
cmd.Parameters.Add(new SqlParameter("@productId", productId));
con.Open();
try
{
cmd.ExecuteNonQuery();
}
finally
{
con.Close();
}
}
public ProductOper()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
}
,8
/Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">








