当前位置: 代码迷 >> .NET面试 >> 字典使用Dictionary 、 datatable.select(),该怎么解决
  详细解决方案

字典使用Dictionary 、 datatable.select(),该怎么解决

热度:67   发布时间:2016-05-02 01:17:21.0
字典使用Dictionary 、 datatable.select()
  //导入到数据库中                            excel数据                                                  对应物理表                                                对应列关系
        public bool process(DataTable xlsdt, Dictionary<string, DataTable> phyTableList, Dictionary<string, Dictionary<string, cell>> columnRelation)
        {
            if (xlsdt != null && xlsdt.Rows.Count > 0)
            {

                string strSql = "";
                string where = "";
                foreach (var item in phyTableList)//循环对应的物理表
                {
                    string phyTableName = item.Key;  //物理表名
                    DataTable dt = item.Value;       //物理表中数据(数据库中)
                    Dictionary<string, cell> phyColumns = columnRelation[phyTableName];//物理表和excle 字段的对应关系
                    int oraCount = dt.Rows.Count;
                    //Dictionary<string, string> xh_Dic = new Dictionary<string, string>();
                    //for (int i = 0; i < dt.Rows.Count; i++)
                    //{
                    //    string key = dt.Rows[i]["xh"].ToString();
                    //    if (key != "")
                    //    {
                    //        xh_Dic.Add(key, i.ToString());
                    //    }
                    //}
                    for (int j = 0; j < xlsdt.Rows.Count; j++)
                    {
                        
                        //string xh = xlsdt.Rows[j][NoRepeatColumn].ToString().Trim();
                        
                        if (oraCount > 0)
                        {
                             where = "";
                             strSql = "";
                             string [] noRepeatList=  this.NoRepeatColumn.Split(',');
                             for (int n = 0; n < noRepeatList.Count(); n++)
                             {
                                 var colitem = noRepeatList[n];
                                 where += phyColumns[colitem].colname + "='" + xlsdt.Rows[j][colitem].ToString().Trim() + "' and  ";

                             }
                             where = where.Trim().Substring(0, where.Trim().Length-3);
                           // DataRow[] tempDr = dt.Select(phyColumns[NoRepeatColumn].colname + "='" + xh + "'");
                             DataRow[] tempDr = dt.Select(where);
                            if (tempDr.Length > 0)
                            //string value;
                            //bool bo = xh_Dic.TryGetValue(xh, out  value);
                            //if (bo)
                            {
                                // strSql = " update miszycj.{3}set xh='{0}',xm='{1}',xb='{2}' where xh='{0}'";
                                strSql = " update miszycj.{0} set  ";
                                foreach (var v in phyColumns)
                                {
                                    if (v.Value.coltype.ToLower() != "date")
                                    {
                                        strSql += v.Value.colname + "= '" + xlsdt.Rows[j][v.Key].ToString().Trim() + "',";
                                    }
                                    else
                                    {
                                        strSql += v.Value.colname + "= to_date('" + xlsdt.Rows[j][v.Key].ToString().Trim() + "','yyyy-mm-dd hh24:mi:ss'),";
                                    }
                                }
                                strSql = strSql.Substring(0, strSql.Length - 1);
                                strSql += "  where  " + where;
                            }
                        }
                        if (strSql == "")
                        {
                            addLsList();
                            strSql = "insert into miszycj.{0} ";
                            string str1 = "";
                            string str2 = "";
                            foreach (var v in phyColumns)
                            {
                                str1 += v.Value.colname + ",";
                                if (v.Value.coltype.ToLower() != "date")
                                {
                                    str2 += "'" + xlsdt.Rows[j][v.Key] + "',";
                                }
                                else
                                {
                                    str2 += "to_date('" + xlsdt.Rows[j][v.Key] + "','yyyy-mm-dd hh24:mi:ss'),";
                                }
                            }
                            str1 = str1.Substring(0, str1.Length - 1);
                            str2 = str2.Substring(0, str2.Length - 1);
                            strSql = "insert into miszycj.{0} ( slid,slidno," + str1 + " ) values ( '"+slid+"','0'," + str2 + " )";

                        }
                        strSql = string.Format(strSql, phyTableName);
                        sqlArry.Add(strSql);
                    }
                }
            }
            bool tag = false;
            if (sqlArry.Count > 0)
            {
                tag = KqDbOperationLibary.atomic.atomic_db.GetDBInstence(DB_INSTANCE.SYSDataSouce).exec_commands(sqlArry);
            }
            return tag;
        }
------解决思路----------------------



LZ这是要干啥啊.. 发这么多帖子


如果是问题 请说问题.

如果是分享 请把代码弄好看点可以不?


------解决思路----------------------
引用:
 就是想保存一下,往后用到好找

把这当笔记本了,csdn要收你钱的
------解决思路----------------------
引用:
 就是想保存一下,往后用到好找


分享可以发布博客,这里是提问区
------解决思路----------------------
  相关解决方案