我在asp.net c#中的购物卡项目遇到da.Fill(ds)错误,>

问题描述 投票:-1回答:1
公共局部类AddToCart:System.Web.UI.Page{受保护的void Page_Load(对象发送者,EventArgs e){如果(!IsPostBack){DataTable dt = new DataTable();DataRow dr;dt.Columns.Add(“ sno”);dt.Columns.Add(“ ProductID”);dt.Columns.Add(“ ProductName”);dt.Columns.Add(“ Price”);dt.Columns.Add(“ ProductImage”);dt.Columns.Add(“ Cost”);dt.Columns.Add(“ TotalCost”);

if (Request.QueryString["id"] != null) { if (Session["Buyitems"] == null) { dr = dt.NewRow(); String mycon = "Data Source=DESKTOP-8C66I6S/SQLEXPRESS;Initial Catalog=haritiShopping;Integrated Security=True"; SqlConnection scon = new SqlConnection(mycon); String myquery = "select * from productdetail where ProductID=" + Request.QueryString["id"]; SqlCommand cmd = new SqlCommand(); cmd.CommandText = myquery; cmd.Connection = scon; SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; DataSet ds = new DataSet(); da.Fill(ds); dr["sno"] = 1; dr["ProductID"] = ds.Tables[0].Rows[0]["ProductID"].ToString(); dr["ProductName"] = ds.Tables[0].Rows[0]["ProductName"].ToString(); dr["ProductImage"] = ds.Tables[0].Rows[0]["ProductImage"].ToString(); dr["Price"] = ds.Tables[0].Rows[0]["Price"].ToString(); dt.Rows.Add(dr); GridView1.DataSource = dt; GridView1.DataBind(); Session["buyitems"] = dt; } else { dt = (DataTable)Session["buyitems"]; int sr; sr = dt.Rows.Count; dr = dt.NewRow(); String mycon = "Data Source=DESKTOP-8C66I6S/SQLEXPRESS;Initial Catalog=haritiShopping;Integrated Security=True"; SqlConnection scon = new SqlConnection(mycon); String myquery = "select * from productdetail where ProductID=" + Request.QueryString["id"]; SqlCommand cmd = new SqlCommand(); cmd.CommandText = myquery; cmd.Connection = scon; SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; DataSet ds = new DataSet(); da.Fill(ds); dr["sno"] = sr + 1; dr["ProductID"] = ds.Tables[0].Rows[0]["ProductID"].ToString(); dr["ProductName"] = ds.Tables[0].Rows[0]["ProductName"].ToString(); dr["ProductImage"] = ds.Tables[0].Rows[0]["ProductImage"].ToString(); dr["Price"] = ds.Tables[0].Rows[0]["Price"].ToString(); dt.Rows.Add(dr); GridView1.DataSource = dt; GridView1.DataBind(); Session["buyitems"] = dt; } } else { dt = (DataTable)Session["buyitems"]; GridView1.DataSource = dt; GridView1.DataBind();

公共局部类AddToCart:System.Web.UI.Page {受保护的无效Page_Load(对象发送者,EventArgs e){如果(!IsPostBack){DataTable dt = new DataTable(); ...
asp.net
1个回答
0
投票
如下更新您的connection string。您没有指定要使用Windows Authentication还是User IdPassword
© www.soinside.com 2019 - 2024. All rights reserved.