I have a datatableof string values.one of the column name target attribute(that column will have maximum 4 different strings ,but all repeated in several rows,repetition of the four strings also not equal) is already known.I had found out which column number it has.again i have to find what are the string values in that column and how many times each string is repeated.
i had written the code successfully for getting two string values if it contains only two using following code
<CODE>
for (int n = 0; n < samples.Columns.Count; n++)
{
if (targetAttribute == samples.Columns[n].ColumnName)
{
classcolumn = n;
}

}
for (int d = 0; d < samples.Columns.Count; d++)
{
if (d == classcolumn)
{
for (int i = 0; i < samples.Rows.Count; i++)
{
value1 = samples.Rows[0][d].ToString();
if ((i != 0) && (samples.Rows[d].ToString() == value1))
{
value1_count++;
}
else if((i!=0) && (samples.Rows[d].ToString()!=value1))
{
value2 = samples.Rows[d].ToString();
value2_count++;
}

}
}
}</CODE>
But if 3 or 4 values,my idea is not working.how can I do it?

i will give an example
column named target has values as follows;

target
--------

yes
yes
no
true
yes
true
no
no
no
false
yes
true
false
no
this column is has 14 values.But the values of the column are unknown to us.so we have to find what are the strings in the column ie we should get yes, no, true,false and respective number of each string.
ie how many yes,how many no like that...

Recommended Answers

All 3 Replies

Can you please have more clarity in your question? Do you want to know how to retrieve values from a database? or do you want to know how to count the number distinct values?

thank you sir for your response...I solved the problem

Please mark the thread solved then.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.