码迷,mamicode.com
首页 > 数据库 > 详细

.net读取Lotus Domino文件数据库并写入DataTable中

时间:2017-04-27 12:33:55      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:session   tin   names   svi   lis   null   字段   style   log   

上一篇文章是简单的读取并输出,这里稍微加深一点,将读取到的内容按字段存入DataTable中。

 1 StringBuilder sb = new StringBuilder();
 2             NotesSession ns = new NotesSession();
 3             //ns.Initialize("test1234");
 4             ns.Initialize();
 5             if (ns == null)
 6             {
 7                 MessageBox.Show("未能初始化");
 8                 return;
 9             }
10             //NotesDatabase db = ns.GetDatabase("", @"names.nsf", false);
11             NotesDatabase db = ns.GetDatabase("", @"todo/120006.nsf", false);
12             if (db == null)
13             {
14                 MessageBox.Show("未能初始化数据库");
15                 return;
16             }
17             NotesView view = db.GetView(@"V5\01.待办文件");
18             if (view == null) return;
19             DataTable dt = new DataTable();
20             object[] cols = view.ColumnNames;
21             Dictionary<int, object> dic = new Dictionary<int, object>();
22             if (cols != null)
23             {
24                 int ix = 0;
25                 foreach (object obj in cols)
26                 {
27                     dic.Add(ix, obj);
28                     if (obj != null)
29                     {
30                         sb.Append(string.Format("{0};", obj));
31                         if (!dt.Columns.Contains(obj.ToString()))
32                         {
33                             DataColumn dc = new DataColumn(obj.ToString());
34                             dt.Columns.Add(dc);
35                         }
36                         
37                     }
38                     ix++;
39                 }
40             }
41             NotesDocument doc = view.GetFirstDocument();
42             while (doc != null)
43             {
44                 object[] objs = (object[])doc.ColumnValues;
45                 if (objs == null) return;
46                 int ix = 0;
47                 DataRow dr = dt.NewRow();
48                 foreach (object obj in objs)
49                 {
50                     if (obj == null) continue;
51                     KeyValuePair<int, object> kv = dic.FirstOrDefault(m => m.Key == ix);
52                     Type tp = obj.GetType();
53                     if (tp.Name.Contains("Object[]"))
54                     {
55                         object[] nobjs = (object[])obj;
56                         List<string> list = new List<string>();
57                         foreach (var nobj in nobjs)
58                         {
59                             sb.Append(string.Format("{0}\r\n", nobj));
60                             list.Add(string.Format("{0}",nobj));
61                         }
62                         dr[kv.Value.ToString()] = string.Join("|", list);
63                     }
64                     else
65                     {
66                         sb.Append(string.Format("{0}\r\n", obj));
67                         dr[kv.Value.ToString()] = obj;
68                     }
69                     ix++;
70                 }
71                 dt.Rows.Add(dr);
72                 doc = view.GetNextDocument(doc);
73             }

 

.net读取Lotus Domino文件数据库并写入DataTable中

标签:session   tin   names   svi   lis   null   字段   style   log   

原文地址:http://www.cnblogs.com/ymworkroom/p/6773448.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!