You can use the following stored proc
CREATE PROCEDURE [dbo].[GetProducts]
@F_Code VARCHAR(100)
AS
BEGIN
SELECT id, [address] ,tell,name, count(behcode) as [count]
FROM furniture_ch, furniture_p
WHERE F_code =@F_Code
ORDER BY furniture_p.date desc
END
In Order by change the "furniture_p.date" to your date column
And for calling this stored proc
String strConnString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "GetProducts";
cmd.Parameters.Add("@F_Code", SqlDbType.VarChar).Value = Request.QueryString["Code"];
cmd.Connection = con;
try
{
con.Open();
GridView1.EmptyDataText = "No Records Found";
GridView1.DataSource = cmd.ExecuteReader();
GridView1.DataBind();
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
con.Dispose();
}