8
Answers

How to get minimum and maximum column count in dataset?

Raja

Raja

8y
238
1
minimum and maximum column count.
 
i refer some websites but little bit cofused.
Answers (8)
0
Bikesh Srivastava

Bikesh Srivastava

NA 19.8k 835k 8y
Hi Raja ,
Try this..
  1. intminAccountLevel=int.MaxValue;
  2. intmaxAccountLevel=int.MinValue;
  3. foreach(DataRowdrintable.Rows)
  4. {
  5. intaccountLevel=dr.Field<int>("AccountLevel");
  6. minAccountLevel=Math.Min(minAccountLevel,accountLevel);
  7. maxAccountLevel=Math.Max(maxAccountLevel,accountLevel);
  8. }
0
Raja

Raja

NA 1.7k 45.3k 8y
Ok i will check it
0
Midhun T P

Midhun T P

NA 19.7k 281.1k 8y
Hi.
There is no rows corresponding to column "Column52" in that dataset. Thats why its throwing error. There should be rows for that column in your dataset for below code to work.
0
Vinay Singh

Vinay Singh

NA 5.9k 126.1k 8y
Hi
check the below solution
  1. DataTable dt= ds.Tables[0];
  2. int min=dt.Compute("min(age)",string.Empty);
  3. int max=dt.Compute(max(age)",string.Empty);
0
Raja

Raja

NA 1.7k 45.3k 8y
Object cannot be cast from DBNull to other types.
Exception error occur
ds.Tables[k].Columns.Add("Column52");
ds.Tables["Source" + c].AcceptChanges();
for (int f = 0; f < ds.Tables[k].Rows.Count; f++)
{

ds.Tables[k].Rows[f]["Column52"] =ds.Tables[k].Compute("MAX(Column52)","");
//double maxval = Convert.ToDouble((ds.Tables[k].Compute("MAX(Column52)", "")));
(also try this one)
}
0
Midhun T P

Midhun T P

NA 19.7k 281.1k 8y
Hi,
Try below code -
double maxval = Convert.ToDouble((dataset.Tables[0].Compute("MAX(colname)", "")));
double minval = Convert.ToDouble((dataset.Tables[0].Compute("MIN(colname)", "")));
0
Raja

Raja

NA 1.7k 45.3k 8y
<h4><a data-userid="9088f9" href="http://www.c-sharpcorner.com/members/midhun-tp">Midhun T P</a></h4>S midhun
0
Midhun T P

Midhun T P

NA 19.7k 281.1k 8y
Hi,
Did you mean the minimum or maximum values in a column of dataset?