Reputation: 3685
I not so good in Linq and I want to make a query to get the right data. I have a Datatable with this columns :
I want to get in the datatable by the Columns TIMEFROM and TIMETO get this = 10.12.2012 not 10.12.2012 00:00:00.
How I can do this: the name of my datatable is table.
MySqlCommand selectcommand = new MySqlCommand(sqlcommand, connection);
MySqlDataAdapter adapter = new MySqlDataAdapter(selectcommand);
DataTable table = new DataTable(TABLE);
adapter.Fill(table);
table = table.AsEnumerable().Where(r => r.Field<int>("Activate") == 1).CopyToDataTable();
//i need the shorter form
connection.Open();
selectcommand.ExecuteReader();
return table;
Upvotes: 0
Views: 157
Reputation: 3307
You will have to create contextclass than create object before you can run the linq command on it. For example your table name is test than you create Linq to Sql class file, drag table test on it. Than on your main program or where ever you need to call it.
testContext ct=new testContext();
var er=from e in ct.test
Select new(e.TIMEFROM, e.TIMETO);
Upvotes: 0
Reputation: 32561
You might want to use
String.Format("{0:dd.MM.yyyy}", dataTable.Rows[0]["TIMEFROM"]);
String.Format("{0:dd.MM.yyyy}", dataTable.Rows[0]["TIMETO"]);
Upvotes: 2