• Trim(',')的作用去除最有一个','


     public bool XMLDataImport()
            {

                List<string> sqllist = new List<string>();
                try
                {
                    XmlDocument x = new XmlDocument();
                    x.Load(txtFilePath.Text);///xml路径  

                    foreach (XmlNode xn in x.ChildNodes)
                    {

                        foreach (XmlNode xn1 in xn.ChildNodes)
                        {
                            string sql = "";
                            string insertValueString = "";
                            string insertColumnString = "";
                            foreach (XmlNode xn2 in xn1.ChildNodes)
                            {
                                ///读取信息 然后导入到数据库
                                insertValueString += string.Format("'{0}',", xn2.InnerText.ToString());
                                insertColumnString += string.Format("{0},", xn2.Name.ToString());
                            }
                            insertColumnString = insertColumnString.Trim(',');
                            insertValueString = insertValueString.Trim(',');
                            sql = string.Format(@"insert into {0}({1}) values({2})", txt_tablename.Text, insertColumnString, insertValueString);
                            sqllist.Add(sql);
                        }

                    }
                    DALUse.ExecuteSqlTran(sqllist.ToArray());
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                return true;
            }

  • 相关阅读:
    Asp.Net中virtual、override理解
    SQL 知道字段名 全表搜索此字段属于哪个表
    C#中(int)a和Convert.ToInt32(a)的区别
    sql 查询表共多少列
    理解字节和字符
    C# IIS7.0+ Web.Config 配置Session过期时间
    Java版的扫雷游戏源码
    Activiti6.0教程 28张表解析 (三)
    Activiti6.0教程 Service用途剖析 (二)
    Activiti6.0教程 Eclipse安装Activiti Diagram插件(一)
  • 原文地址:https://www.cnblogs.com/wuhailong/p/3767381.html
Copyright © 2020-2023  润新知