private void btn_save_Click(object sender, EventArgs e)
 {
     try
     {
         cf.WaitingThreadStart();
         foreach (DataRow dr in dtcompare.Rows)
         {
             if (dr["NEWROWFLAG"].ToString() == "1")//当时才插入为新插入行
             {
                 string sqlupdate = string.Format("update PT_COMPARISON_DETAIL_DICT set compare_name='{0}',compare_code='{1}'where id = '{2}'",
                                                  dr["COMPARE_NAME"].ToString().Replace("'", "''"),
                                                  dr["COMPARE_CODE"].ToString().Replace("'", "''"),
                                                  dr["ID"].ToString());
                 sqllist.Add(sqlupdate);
             }
         }
         bool result = DALUse.ExecuteSqlTran(sqllist.ToArray());
         cf.WaitingThreadStop();
         InitData();
         if (result)
         {
             MessageBox.Show("数据保存成功!");
         }
     }
     catch (Exception ex)
     {
         string serror = "";
         foreach (string s in sqllist)
         {
             serror += s + "\n";
         }
         MessageBox.Show(serror + ex.ToString());
     }
 }
示例#2
0
        public void InsertIntoTable(DataSet ds)
        {
            #region 将生成的dataset存入数据库
            List <string> sqllist = new List <string>();
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                string sql = "";
                string insertValueString  = "";
                string insertColumnString = "";
                foreach (DataColumn dc in ds.Tables[0].Columns)
                {
                    ///读取信息 然后导入到数据库
                    insertValueString  += string.Format("'{0}',", dr[dc].ToString());
                    insertColumnString += string.Format("{0},", dc.ToString());
                }
                insertColumnString = insertColumnString.Trim(',');
                insertValueString  = insertValueString.Trim(',');
                sql = string.Format(@"insert into {0}({1}) values({2})", txt_dict_name.Text, insertColumnString, insertValueString);
                sqllist.Add(sql);
            }

            try
            {
                DALUse.ExecuteSqlTran(sqllist.ToArray());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            #endregion
        }
 public void SaveAndUpdate()
 {
     try
     {
         DALUse.ExecuteSqlTran(sqllist.ToArray());
     }
     catch (Exception)
     {
         throw;
     }
     MessageBox.Show("保存操作完成!");
     InitData();
 }
示例#4
0
        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_dict_name.Text, insertColumnString, insertValueString);
                        sqllist.Add(sql);
                    }
                }
                DALUse.ExecuteSqlTran(sqllist.ToArray());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return(true);
        }