select with index on DataTable?
After I get DataTable from sqlAdapter I'm clos开发者_Python百科ing connection. If I preform SELECT from this DataTable, does the select use the index I created in the DB?
what code do I need to write for using the index?
If I understand your question, you want to know if the index that's defined in the DB will be present in the DataTable? Unfortunately the answer is no, the DataTable is separate from the database.
See this: Do ADO.Net DataTables have indexes?
If you've already selected your data from the database and placed it into an in-memory table, you won't have access to the db's indicies. However, because the table is now in-memory, you won't need those indicies, as the lookup performance will be improved due to the fact that it is an in-memory search.
All data in the DataTable is respecting database structure/data, you have exactly what you have in the database.
DataRow[] dra = datatable.Select("uid > 2");
foreach (DataRow dr in dra)
{
Console.WriteLine(dr["uid"]);
}
A DataTable
is an in-memory dataset. If you (sub)select after it has been fetched from the DB you're query your data in memory and you're not using an index.
Select all of the rows in the DataTable
int rowNumber DataRow[] foundrow; String showString;
foundrow = yourDataSet.Tables["yourTableName"].Select();
Select the specific row and column(s)
showString = foundrow[rowNumber]["yourColumnName"].ToString();
精彩评论