in my web application i am using datatable and inserting outlook contacts in that. this is my code
DataTable myTable = new DataTable();
DataRow dr = myTable.NewRow();
DataColumn myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.String");
myDataColumn.ColumnName = "Email";
myTable.Columns.Add(myDataColumn);
Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
foreach (Microsoft.Office.Interop.Outlook.AddressList addList in oApp.Session.AddressLists)
{
foreach (Microsoft.Office.Interop.Outlook.AddressEntry addEntry in addList.AddressEntries)
{
开发者_运维问答 dr["Email"] = addEntry.Address.ToString();
myTable.Rows.Add(dr);
dr = myTable.NewRow();
//Response.Write(addEntry.Address.ToString());
}
}
My doubt is can i write the code like this when contact is insert into mytable. the details of the row can read into a string like this
string s= myTable.Rows[0]["Email"].ToString(); in foreach
You can use the DataRow collection of the foreach loop and get the corresponding row values.
foreach (DataRow dr in myTable.Rows)
{
// Specify the column name or column index of the datacolumn
//dr["ColumnName"].ToString();
}
or you can use a DataView of the DataTable and iterate through the DataRowView collection
DataView dv = myTable.DefaultView;
foreach (DataRowView drv in dv)
{
drv.Row["ColumnName"].ToString();
}
精彩评论