Selecting the particular column value from the datatable in ASP.net

Posted by Gokul under Regular Expressions on 4/11/2011 | Points: 10 | Views : 25967 | Status : [Member] | Replies : 9
Dear Friends,
I want to get the particular value from the datatable. For an example, Consider there is a datatable dtemp that contains the result of all the values fron DB by using "Select * from EMPLOYEETABLE". Those values from the DB are stored in a datatable dtemp. Now from that datatable dtebp, we want to get only the Employee Name and we want to get all the Employee Name from dtemp datatable into another datatable say dtresult. Can any help me in solving out.



Thanks and Regards
Gokul.Nithy

Thanks and Regards,
GokulNath Nithy.



Responses

Posted by: Gsolvers on: 4/11/2011 [Member] Starter | Points: 25

Up
0
Down
Use the below pseudococe
loop on datatable.rows.count
datatable.columns("EmployeeNAme") ' You can assign to any array or new datatable
end loop

Best Regards,

VG
www.TeacherJi.com

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

Posted by: Karthikanbarasan on: 4/11/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Simple option is you can use FILTER in datatable... and one more option is using the importrow... check the below links

http://www.c-sharpcorner.com/UploadFile/mahesh/ImportRow07092006195427PM/ImportRow.aspx

http://www.dotnetspider.com/resources/4555-How-filter-e-datatable.aspx

Thanks
Karthik
www.f5Debug.net

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

Posted by: Gsolvers on: 4/11/2011 [Member] Starter | Points: 25

Up
0
Down
yea that should works

Best Regards,

VG
www.TeacherJi.com

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

Posted by: Karthikanbarasan on: 4/11/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Which one Gsolvers?

Thanks
Karthik
www.f5Debug.net

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

Posted by: Gsolvers on: 4/11/2011 [Member] Starter | Points: 25

Up
0
Down
That was the usage of Filter in datatables

Best Regards,

VG
www.TeacherJi.com

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

Posted by: Karthikanbarasan on: 4/11/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
oops ok :)

Thanks
Karthik
www.f5Debug.net

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

Posted by: Gsolvers on: 4/11/2011 [Member] Starter | Points: 25

Up
0
Down
:)

Best Regards,

VG
www.TeacherJi.com

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

Posted by: NDebata on: 4/13/2011 [Member] Starter | Points: 25

Up
0
Down
//Populating data table with some sample data.

DataTable dtemp = new DataTable();
dtemp.Columns.AddRange(new DataColumn[] { "EmpID", "EmpName", "SomeColumn" });
for (int i = 0; i < 10; i++)
{
dtemp.Rows.Add(new object[] { "Emp" + i, "Name_" + i, "Test_Value" + i });
}

// Find the index of the required column in data table
var empNamePos=dtemp.Columns.Cast<DataColumn>().ToList().FindIndex(c=>c.ColumnName.Equals("EmpName",StringComparison.OrdinalIgnoreCase);

DataTable dtresult = new DataTable();
dtresult.Columns.Add("EmployeeName");

foreach (DataRow item in dtemp.Rows)
{
dtresult.Rows.Add(item[empNamePos]);
}


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

Posted by: Susanthampy on: 5/24/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,

Refer this link,

http://gchandra.wordpress.com/2008/01/07/aspnet-filter-datatable-by-column/

Regards,
Susan

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

Login to post response