Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

XML
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.. :( :(


This is the .class file

C#
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;
    }

}
Posted
Updated 6-May-14 4:49am
v3
Comments
Telstra 6-May-14 10:17am    
what you tried so far? post your efforts here please
ZurdoDev 6-May-14 10:19am    
Do you have a question?
[no name] 6-May-14 10:25am    
If you are having "problems" you have to tell us what those problems are. Telling us "I want" is not a question or a description of any kind of a problem. What exactly is it that you find difficult about connecting to your database and querying for the data that you want?
thatraja 6-May-14 10:39am    
Not enough details. Update your question

I think you should filter the resultset using WHERE condition.
J. Chatterjee 6-May-14 10:44am    
Lol.. I have updated the question.. :P :P

1 solution

I do not see you calling your data_Fetch or INUPDL methods anywhere.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900