Wednesday, March 21, 2012

Hi Need Help

I have an application in c#. Which is intended to give student with highest marks in each class.

There are 10 classes

The requirement is to find top student of each class and display it in columnwise like below

Class Student Name

Can anyone help me on that.

Thanks in advance

Hi,

Prepare the SQL Query which returns the Top 10 values from each class vise..

Select Top 10 Stud-ID,Stud_Name from StudentTable where StudentClass = UserParameter;

Write the C# Method which accept the One Parameter from the User and return the result set.

public DataSet GetTopTen(string strClassParam)
{
ds = new DataSet();
if (ObjCon.State == ConnectionState.Open) ObjCon.Close();
ObjCon.Open();
string strQuery = "Select Top 10 Stud-ID,Stud_Name from StudentTable where StudentClass ="+strClassParam; (Change the Query according to your need..)
sc = new SqlCommand(strQuery, ObjCon);
sda = new SqlDataAdapter(sc);
sda.Fill(ds);
ObjCon.Close();
return ds;
}

Biind the Result Set to the DataGrid or Gridview to show it.

That is it.

|||

hi,

i assume that u r geeting yr data from sql qury. if so, then u can get ur data by firing such query

selectdistinct class,studentnamefrom studenttablewhere mark=(selectmax(mark)from studenttable)

you can getthis by declaring dataset.u can bind gridview withclass and studentname bounded columns and assigning datasource to it like

gridview1.datasource = ds.tables[0].defaultview;

gridview1.databind();

No comments:

Post a Comment