在使用数据库中的数据填充数据集时遇到问题

问题描述:

我在products表中创建了一个包含多个值(pcode)的会话。在Cart.aspx页面上,我能够获取pcodes,但我想从数据集中的数据库中检索所有具有这些pcode的行。



I have created a session containing multiple values(pcode) from products table. on Cart.aspx page, I am able to get the pcodes, but I want to retrive all the rows having those pcodes from the database in a dataset.

I am able to retrieve the pcodes in a datalist:
this is the cart.aspx file code

<pre lang="c#"><![CDATA[<%@ Page Title="E-Cart" Language="C#" MasterPageFile="~/shopmaster.master" AutoEventWireup="true" CodeFile="Cart.aspx.cs" Inherits="Cart" %>]]>


<asp:content id="Content1" contentplaceholderid="head" runat="Server" xmlns:asp="#unknown">
    <style type="text/css">
        .style45
        {}
        .style46
        {
            width: 66%;
            height: 105px;
        }
        .style49
        {}
        .style50
        {
            width: 698px;
        }
    </style>
</asp:content>
<asp:content id="Content2" contentplaceholderid="ContentPlaceHolder1" runat="Server" xmlns:asp="#unknown">
    <asp:panel id="Panel4" runat="server" cssclass="style45" height="302px">
        <table class="style46">
            <tr valign="top">
                    <br />
                    <asp:datalist id="DataList1" runat="server">
                        <itemtemplate>
                            PCode:
                            <asp:label id="Label_pcode" runat="server" text="&lt;%#Eval("pcode")%&gt;"></asp:label>
                        </itemtemplate>
                    </asp:datalist>
                    <br />
                    <asp:label id="Label1" runat="server" text="Label"></asp:label>

                <td valign="top">
                    <asp:button id="Button_AddMore" runat="server" cssclass="style49" height="34px">
                        onclick="Button_AddMore_Click" Text="Add More Items" Width="143px" /&gt;
                    <br />
                    <asp:button id="Button_AddMore0" runat="server" cssclass="style49">
                        Height="34px" onclick="Button_AddMore_Click" Text="Proceed to Payment"
                        Width="143px" /&gt;
                </asp:button></asp:button></td>
            </tr>
        </table>
        <br />
    </asp:panel>
</asp:content>

</pre>


this is the Cart.aspx.cs file code

<pre lang="c#">using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data;


public partial class Cart : System.Web.UI.Page
{
    Classdataconn con = new Classdataconn();
    DataTable dt1 = new DataTable();

    protected void Page_Load(object sender, EventArgs e)
    {
        dt1.Columns.Add("pcode");

        if (Session["sess_pcodes"] != null)
        {
            dt1.Clear();
            dt1 = (DataTable)Session["sess_pcodes"];
            BindData(dt1);
        }
    }

    protected void BindData(DataTable dt)
    {
        DataList1.DataSource = dt1;
        DataList1.DataBind();
    }
    protected void Button_AddMore_Click(object sender, EventArgs e)
    {
        Response.Redirect("products.aspx");
    }

}</pre>

I want to get the corresponding rows from the database against those pcode in the datalist.. Kindly help.. :( :(





这是.class文件





This is the .class file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

/// <summary>
/// Summary description for Classdataconn
/// </summary>
public class Classdataconn
{
    SqlConnection con;
    public Classdataconn()
    {
        //
        // TODO: Add constructor logic here
        //
    }
    public SqlConnection conn_connect()
    {
        con = new SqlConnection(ConfigurationManager.ConnectionStrings["connection"].ToString());
        return con;
    }


    public void INUPDL(string st)
    {
        SqlCommand com = new SqlCommand();
        com.Connection = conn_connect();
        com.CommandText = st;
        con.Open();
        com.ExecuteNonQuery();
        con.Close();




    }
    public DataSet data_Fetch(string ss)
    {
        SqlDataAdapter adpt = new SqlDataAdapter(ss, conn_connect());
        DataSet ds = new DataSet();
        adpt.Fill(ds);
        return ds;
    }

}

我没有看到你打电话给 data_Fetch INUPDL 方法。
I do not see you calling your data_Fetch or INUPDL methods anywhere.