using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;using System.Data.OleDb;public partial class fenye_Gou_Wu_Che : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ //购物车信息显示
this.Label1.Text = "请确认您的购物清单"; //给出数据库路径和连接方式
string strPath = "App_Data/db.mdb";
string strConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + HttpContext.Current.Request.ServerVariables["APPL_PHYSICAL_PATH"] + strPath; //生成OleDbConnection实例,构建数据库连接
OleDbConnection cn = new OleDbConnection(strConStr);
cn.Open(); //构建数据库实例
DataSet ds = new DataSet(); //构建表实例
DataTable dt = ds.Tables.Add("GouWuChe");
//构建表结构
dt.Columns.Add("id", typeof(string));
dt.Columns.Add("zc", typeof(string));
dt.Columns.Add("zname", typeof(string));
dt.Columns.Add("xg", typeof(string));
dt.Columns.Add("price", typeof(string));
//定义键
DataColumn[] myKey = new DataColumn[1];
myKey[0] = dt.Columns["id"]; //将Session里的数据提取出来,并显示
string strSessionID = Convert.ToString(Session["id"]);
string[] strSessionIDS = strSessionID.Split('&');
for (int i = 0; i < strSessionIDS.Length - 1; i++)
{
string DataID = "id=" + strSessionIDS[i]; //给出SQL语句
string strSQL = "Select * From zs Where " + DataID;
//构建OleDbCommand实例,导出数据
OleDbCommand com = new OleDbCommand(strSQL, cn);
//构建OleDbDataReader实例,载入数据
OleDbDataReader oddr = com.ExecuteReader(CommandBehavior.CloseConnection);
oddr.Read();
//将oddr(OleDbDataReader)里的数据添加到dt(DataTable)
DataRow dr = dt.NewRow();
dr[0] = oddr[0].ToString();
dr[1] = oddr[1].ToString();
dr[2] = oddr[2].ToString();
dr[3] = oddr[3].ToString();
dr[4] = oddr[4].ToString();
dt.Rows.Add(dr);
}
cn.Close(); this.GridView1.DataSource = ds;
this.GridView1.DataKeyNames = new string[] { "id" };
this.GridView1.DataBind();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int intSelectLineNo = Convert.ToInt32(GridView1.Rows[e.RowIndex].RowIndex.ToString()); //将与之对应的Session里的数据删除
string strSessionID = Convert.ToString(Session["id"]);
string[] strSessionIDS = strSessionID.Split('&');
strSessionID = "";
for (int i = 0; i < strSessionIDS.Length - 1; i++)
{
if (intSelectLineNo == i)
{
continue;
}
else
{
strSessionID = strSessionID + strSessionIDS[i] + "&";
}
}
Session["id"] = null;
Session["id"] = strSessionID; Response.Redirect("Gou_Wu_Che.aspx");
}
}这是我的购物车页面代码,只能加一个表中数据库到购物车,怎么改可以吧三个表的数据加入同一个购物车?
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;using System.Data.OleDb;public partial class fenye_Gou_Wu_Che : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ //购物车信息显示
this.Label1.Text = "请确认您的购物清单"; //给出数据库路径和连接方式
string strPath = "App_Data/db.mdb";
string strConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + HttpContext.Current.Request.ServerVariables["APPL_PHYSICAL_PATH"] + strPath; //生成OleDbConnection实例,构建数据库连接
OleDbConnection cn = new OleDbConnection(strConStr);
cn.Open(); //构建数据库实例
DataSet ds = new DataSet(); //构建表实例
DataTable dt = ds.Tables.Add("GouWuChe");
//构建表结构
dt.Columns.Add("id", typeof(string));
dt.Columns.Add("zc", typeof(string));
dt.Columns.Add("zname", typeof(string));
dt.Columns.Add("xg", typeof(string));
dt.Columns.Add("price", typeof(string));
//定义键
DataColumn[] myKey = new DataColumn[1];
myKey[0] = dt.Columns["id"]; //将Session里的数据提取出来,并显示
string strSessionID = Convert.ToString(Session["id"]);
string[] strSessionIDS = strSessionID.Split('&');
for (int i = 0; i < strSessionIDS.Length - 1; i++)
{
string DataID = "id=" + strSessionIDS[i]; //给出SQL语句
string strSQL = "Select * From zs Where " + DataID;
//构建OleDbCommand实例,导出数据
OleDbCommand com = new OleDbCommand(strSQL, cn);
//构建OleDbDataReader实例,载入数据
OleDbDataReader oddr = com.ExecuteReader(CommandBehavior.CloseConnection);
oddr.Read();
//将oddr(OleDbDataReader)里的数据添加到dt(DataTable)
DataRow dr = dt.NewRow();
dr[0] = oddr[0].ToString();
dr[1] = oddr[1].ToString();
dr[2] = oddr[2].ToString();
dr[3] = oddr[3].ToString();
dr[4] = oddr[4].ToString();
dt.Rows.Add(dr);
}
cn.Close(); this.GridView1.DataSource = ds;
this.GridView1.DataKeyNames = new string[] { "id" };
this.GridView1.DataBind();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int intSelectLineNo = Convert.ToInt32(GridView1.Rows[e.RowIndex].RowIndex.ToString()); //将与之对应的Session里的数据删除
string strSessionID = Convert.ToString(Session["id"]);
string[] strSessionIDS = strSessionID.Split('&');
strSessionID = "";
for (int i = 0; i < strSessionIDS.Length - 1; i++)
{
if (intSelectLineNo == i)
{
continue;
}
else
{
strSessionID = strSessionID + strSessionIDS[i] + "&";
}
}
Session["id"] = null;
Session["id"] = strSessionID; Response.Redirect("Gou_Wu_Che.aspx");
}
}这是我的购物车页面代码,只能加一个表中数据库到购物车,怎么改可以吧三个表的数据加入同一个购物车?
解决方案 »
- winform中嵌入dsoframe后调用VBA问题求助
- 这个算法应该怎样弄?数值?集合?
- 下载了套源码,用vs打开运行后,貌似数据库不能打开
- 关于C#中数据库的问题
- 碰到个不好处理的字符串处理问题,请大家指点一下!
- 能否在不启动vs2008的情况下编译整个solution?
- 页面上的js正则表达式通过之后,怎麽通知*.aspx.vb文件访问数据库!
- Remoting连接与CS连接的问题
- pc端怎么控制座机?
- 请问在ASP.NET Web应用中如何接收电子邮件
- C#对devexpress.xtraGrid.Views.Grid.GridView中不包含Rows的定义并且找不到可接受类型为
- 紧急求助,IList<T>问题
Session["Order"]=字典集合 key表示相应的表,value就是相关的id集合或者根据几个表分别创建Session["id1"] Session["id2"]....将记录加入