datatable - Adding the column result of a DataRow[] column to a variable c# -


i want return value of datarow[] string in c#

here datatable:

datatable table = new datatable();             table.columns.add("id", typeof(int));             table.columns.add("bugdescription", typeof(string));             table.columns.add("unitprice", typeof(double));              table.rows.add(1, "bug 1", 10.00);             table.rows.add(2, "bug 2", 20.00); 

i create datarow[] called result stores row id = 1:

datarow[] result = table.select("id = 1"); 

the last step want achieve add bugdescription value string named description.

how achieve this?

your code

datarow[] result = table.select("id = 1"); 

tells you have got array of datarows. means may have more 1 record here. so, depends on row assign. can if think first one

if(result.length > 0) {    string description = convert.tostring(result[0]["bugdescription"]);  } 

doing linq way

string description = table.rows.oftype<datarow>().where(row => (string)row["id"] == "1").select(row => (string)row["bugdescription"]).first(); 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -