0

my aspx code

   <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><asp:DataList ID="DataList1"
        runat="server" DataSourceID="SqlDataSource1" 
>
        <ItemTemplate>
            Product_Image:
            <asp:Label ID="Product_ImageLabel" runat="server" 
                Text='<%# Eval("Product_Image") %>' />
            <br />
            Item_Description:
            <asp:Label ID="Item_DescriptionLabel" runat="server" 
                Text='<%# Eval("Item_Description") %>' />
            <br />
            Price:
            <asp:Label ID="PriceLabel" runat="server" Text='<%# Eval("Price") %>' />
            <br />
            Qty:
            <asp:Label ID="QtyLabel" runat="server" Text='<%# Eval("Qty") %>' />
            <br />
            Total:
            <asp:Label ID="TotalLabel" runat="server" Text='<%# Eval("Total") %>' />
            <br />
            <br />
        </ItemTemplate>
    </asp:DataList>
    <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]">
    </asp:SqlDataSource>

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";
    con.Open();
    SqlCommand cmd1 = new SqlCommand("select * from Cart1", con);
    SqlDataReader dr1 = cmd1.ExecuteReader();
    dr1.Close();
    SqlCommand cmd2 = new SqlCommand("select * from Cart1 where Customer_ID='" + TextBox1.Text+ "'", con);
    SqlDataReader dr2 = cmd2.ExecuteReader();

    if (dr2.Read())
    {
        DataTable dt = new DataTable();
        dt.Load(dr2);
        DataList1.DataSourceID = null;
        DataList1.DataSource = dt;
        DataList1.DataBind();
    }

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

2
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by crazydevelopervish
0

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

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.