Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET SQL-Server
Sir,
 
This is code for Search Query on multiple criteria filled by user. I am firing this query and storing result in datatable and storing that datatable in session and retreving this session on another page to display search result in listview.
 
My problem is that, I want to count the number of records return by this query and display them on search Result page on top for
eg: 25 Records found or if no record found display no record found..
SqlConnection con = new SqlConnection(str);
            string strQ = ("select s.Property_ID,s.Property_For,s.Property_Type,s.Property_Name,C.City_Name,L.Locality_Name,s.Price,s.Bedroom,s.Area,s.ImageName,s.ImagePath From tbl_Post_Property as s inner join tbl_City as C on C.City_Id=s.City_id inner join tbl_Locality as L on L.Locality_Id=s.Locality_Id where Property_For='"+ rbtnsearch.SelectedItem.Text +"' and s.Property_type='" + ddlpropertytype.SelectedItem.Text + "' and C.City_Id=" + ddlcity.SelectedValue + " and L.Locality_Id=" + ddllocality.SelectedValue + " and s.price between " + ddlminprice.SelectedValue + " and " + ddlmaxprice.SelectedValue + "");
            con.Open();
            SqlDataAdapter da = new SqlDataAdapter(strQ, con);
            DataTable dt = new DataTable();
            da.Fill(dt);
            Session["Search"] = dt;
            con.Close();
            Response.Redirect("SearchResult.aspx", false);
Searchresult Page
DataTable dt = new DataTable();
        dt = Session["Search"] as DataTable;         
        listview1.DataSource = dt;
        listview1.DataBind();
Posted 18-Oct-12 2:00am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

int rowcount = dt.rows.count();
will give you the number of records fetched.
  Permalink  
v2
Comments
Raj.Rautela at 18-Oct-12 7:56am
   
thanks sir
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

you can put a label on the top of your flied and set the the value like this..
 
Label1.Text = Covert.ToString(dt.Rows.Count)+"Records found ";
 
you can use conditional staement if you need to set message for zero rows
  Permalink  
Comments
Raj.Rautela at 18-Oct-12 7:56am
   
thanks sir
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Use the code as below.
if(dt.Rows.Count > 0)
{
     lblSearchResultText.Text = Covert.ToString(dt.Rows.Count) + " Records found.";
}
else
{
     lblSearchResultText.Text = "No records found.";
}
Comments
Raj.Rautela at 18-Oct-12 7:24am
   
thanks sir..
Tadit Dash at 18-Oct-12 8:43am
   
Hi Raj,
 
Thanks for accepting the answer.
 
Regards,
Tadit
Tadit Dash at 18-Oct-12 7:30am
   
Hi Raj,
 
Anytime, my pleasure...
Please accept this answer, if it has helped you in any way.
This will help others to find the answer in one go and you will also be awarded with some points for this action...
 
Thanks,
Tadit

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

  Print Answers RSS
0 OriginalGriff 490
1 Maciej Los 299
2 BillWoodruff 174
3 /\jmot 170
4 Suraj Sahoo | Coding Passion 150
0 OriginalGriff 8,484
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,159
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 18 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100