标签:
void IDataAccess.CommandDataTable(DataTable dt, string ProcedureName, System.Data.Common.DbParameter[] para)
{
_sqlConnection = new SqlConnection(strConnet);
SqlDataAdapter MyAdapter = new SqlDataAdapter();
MyAdapter.InsertCommand = new SqlCommand();
MyAdapter.InsertCommand.CommandType = CommandType.StoredProcedure;
MyAdapter.InsertCommand.CommandText = ProcedureName;
MyAdapter.InsertCommand.Connection = _sqlConnection;
foreach (SqlParameter parm in para)
MyAdapter.InsertCommand.Parameters.Add(parm);
MyAdapter.Update(dt);
if (_sqlConnection != null)
{
_sqlConnection.Close();
}
GC.Collect();
}
public System.Data.DataTable CreateCartTable()
{
System.Data.DataTable dt = new System.Data.DataTable();
System.Data.DataRow dr;
dt.Columns.Add(new System.Data.DataColumn("UserID"));
dt.Columns.Add(new System.Data.DataColumn("ProductID"));
dt.Columns.Add(new System.Data.DataColumn("Count"));
IDataReader reader = new MssqlDataReader();
string[] s = Request.QueryString["ids"].ToString().Split(new char[] { ‘,‘ });
if (s != null && s.Length > 0)
{
for (int i = 0; i < s.Length; i++)
{
TempCart[] tc = reader.GetTempCartByID(Convert.ToInt32(s[i]));
if (tc.Length > 0)
{
dr = dt.NewRow();
dr[0] = Session["ID_Member"].ToString();
dr[1] = tc[0].ProductID.ToString();
dr[2] = tc[0].Count.ToString();
dt.Rows.Add(dr);
}
}
}
return dt;
}
void IDataWriter.AddCartMore(DataTable dt)
{
IDataAccess access = DataCenter.GetDbConnection();
SqlParameter[] para ={
new SqlParameter("@UserID",SqlDbType.Int),
new SqlParameter("@ProductID",SqlDbType.Int),
new SqlParameter("@Count",SqlDbType.Int)
};
para[0].SourceColumn = dt.Columns[0].ColumnName;
para[1].SourceColumn = dt.Columns[1].ColumnName;
para[2].SourceColumn = dt.Columns[2].ColumnName;
access.CommandDataTable(dt, "Sy_Cart_Add", para);
}
标签:
原文地址:http://www.cnblogs.com/sky6699/p/4892487.html