my aspx code

   <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><asp:DataList ID="DataList1"
        runat="server" DataSourceID="SqlDataSource1" 
            <asp:Label ID="Product_ImageLabel" runat="server" 
                Text='<%# Eval("Product_Image") %>' />
            <br />
            <asp:Label ID="Item_DescriptionLabel" runat="server" 
                Text='<%# Eval("Item_Description") %>' />
            <br />
            <asp:Label ID="PriceLabel" runat="server" Text='<%# Eval("Price") %>' />
            <br />
            <asp:Label ID="QtyLabel" runat="server" Text='<%# Eval("Qty") %>' />
            <br />
            <asp:Label ID="TotalLabel" runat="server" Text='<%# Eval("Total") %>' />
            <br />
            <br />
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:OnlineShopConnectionString2 %>" 

        SelectCommand="SELECT [Product_Image], [Item_Description], [Price], [Qty], [Total] FROM [Cart1]">

My .cs file
on button click

    SqlConnection con = new SqlConnection();
    con.ConnectionString = "Data Source=HP-HP\\SQLEXPRESS;Initial Catalog=OnlineShop;Persist Security Info=True;User ID=sa;Password=rane@1234";
    SqlCommand cmd1 = new SqlCommand("select * from Cart1", con);
    SqlDataReader dr1 = cmd1.ExecuteReader();
    SqlCommand cmd2 = new SqlCommand("select * from Cart1 where Customer_ID='" + TextBox1.Text+ "'", con);
    SqlDataReader dr2 = cmd2.ExecuteReader();

    if (dr2.Read())
        DataTable dt = new DataTable();
        DataList1.DataSourceID = null;
        DataList1.DataSource = dt;

now the problem when i search for the product based on customer_id given from textbox it retrives 1 record less that two starting record.
For example if i enter 9 it retrives the record from database whose customer_id is 9 but if the customer have buy 10 products it only show 9.

Pls Help

Recommended Answers

All 2 Replies

You validated that your SQL queries produce the expected results outside of your aspx application? For example, run the queries in SQL Mgmt Studio.

Yes i have tried it ... SQL management studio shows 10 records belong to customer_id=9 but show only 9 records in datalist

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.