How can i determine the index of a row in a dataset if one column value is known?
here the code to fill the data set:
string str = "SELECT ROUND(AVG((EXAMRESULTS.assessM1 + EXAMRESULTS.assessM2 + EXAMRESULTS.assessM3)/3), 2), STUDENT.studentId FROM EXAMRESULTS, STUDENT where EXAMRESULTS.Term = '" + comboBox15.Text + "' AND EXAMRESULTS.class = '" + comboBox14.Text + "' AND EXAMRESULTS.StudentId = STUDENT.studentId GROUP BY STUDENT.studentId, EXAMRESULTS.StudentId ORDER BY AVG((EXAMRESULTS.assessM1 + EXAMRESULTS.assessM2 + EXAMRESULTS.assessM3)/3) DESC";
The i want to know the row that will have a particular STUDENT.studentId (say the id = 23)
Loading

Sandeep Singh ShekhawatPosted Jun 1, 2013, 11:35 PM
Hi ablafizi kibiki,
Suppose I have an Employee table and ID is a primary key in Employee table and I want to index in data set which Employee has ID =2 then write below code (DataSet contains one or more table)
protected void Page_Load(object sender, EventArgs e)
{
string conStr = "Data Source=sandeepss-PC;Initial Catalog=Tutorial;User ID=sa;Password=*****";
string str = "Select * From Employee";
SqlConnection con = new SqlConnection(conStr);
if(con.State==ConnectionState.Closed)
con.Open();
SqlDataAdapter dap = new SqlDataAdapter(str,con);
DataSet ds = new DataSet();
dap.FillSchema(ds, SchemaType.Source, "Employee");
dap.Fill(ds,"Employee");
DataTable dt = ds.Tables["Employee"];
int index = getIndex(dt, 2);
}
//It will return index of row which in table of dataset
public int getIndex(DataTable dt, object myvalue)
{
DataRow dr = dt.Rows.Find(myvalue);
if (dr != null)
return dt.Rows.IndexOf(dr);
return -1;
}