how to update rank in c#

Posted by Sekar.C under C# on 3/29/2012 | Points: 10 | Views : 1098 | Status : [Member] | Replies : 2
hi,
I want rank the flats based on the (Hospitals, Restaurants, Transports, Markets)iscore
I use this coding line .if I rank single flat this code is work but if I rank bulk data(select flatid in drop down) it update the rank in all flatshow can solve this problem

I used this stored procedure
Create proc [dbo].[sp_FlatRank](@flatID varchar(50))
as
update Flats set FlatRank=(select
ISNULL((select max(IScore) from Flats f inner JOIN Hospitals h on f.FlatID=h.FlatID),0)+
ISNULL((select max(IScore)from Flats f inner JOIN Restaurants r on f.FlatID=r.FlatID),0)+
ISNULL((select max(IScore) from Flats f inner JOIN Transports t on f.FlatID=t.FlatID),0)+
ISNULL((select max(IScore) from Flats f inner JOIN Markets m on f.FlatID=m.FlatID),0) )
where flatId=@flatId

this my ranking code
if (con_db.Connect_Database() == true)
{
con_db.con.Open();
SqlCommand cmd = new SqlCommand("select FlatRank from flats where flatid='"+ddlrank.SelectedItem.Text+"'",con_db.con);
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read() == true)
{
string rank = sdr[0].ToString();
if (rank == "0" || rank =="")
{

sdr.Dispose();
SqlCommand cmd1 = new SqlCommand("sp_FlatRank", con_db.con);
cmd1.CommandType = CommandType.StoredProcedure;
cmd1.Parameters.AddWithValue("@FlatID", ddlrank.SelectedItem.Text);
cmd1.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter("select FlatID,Flatname,FlatLocation,FlatSize,FlatPrice,FlatStatus,DistanceRef,Distance, ROUND(FlatRank , 0)as FlatRank from flats where FlatID='" + ddlrank.SelectedItem.Text + "'", con_db.con);
DataSet ds = new DataSet();
da.Fill(ds, "Flats");
GridView1.DataSource = ds.Tables["Flats"];
GridView1.DataBind();


}
else
{
sdr.Dispose();
SqlDataAdapter da = new SqlDataAdapter("select FlatID,Flatname,FlatLocation,FlatSize,FlatPrice,FlatStatus,DistanceRef,Distance, ROUND(FlatRank , 0)as FlatRank from flats where FlatID='" + ddlrank.SelectedItem.Text + "'", con_db.con);
DataSet ds = new DataSet();
da.Fill(ds, "Flats");
GridView1.DataSource = ds.Tables["Flats"];
GridView1.DataBind();
}
}
con_db.con.Close();

}
else
{
Response.Write("The Needed database is not connected");
}


regards
sekar.c

Regards
Sekar.c



Responses

Posted by: Subhacomm on: 3/30/2012 [Member] Starter | Points: 25

Up
0
Down
How are u ranking the 'bulk data' where you can only select a single flatid from drop down at a time.. please explain

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajni.Shekhar on: 3/30/2012 [Member] Bronze | Points: 25

Up
0
Down
i think, this code will work for one data, there is no code for bulk data.
you are only passing selecting item in your code.

ddlrank.SelectedItem.Text

Thanks,
Rajni Shekhar

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response