首页 > 其他 > 详细

insert语句太长,有StringBuilder优化一下

时间:2014-05-09 14:53:59      阅读:434      评论:0      收藏:0      [点我收藏+]

 private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            if (IsInsert)
            {
                //如果日历控件没有选日期,那帮它赋一个当前日期。下面有三个日历控件。我这里指为一个日历控件做了这样的设置
                DateTime time1 = dpEditTime.SelectedDate == null ? DateTime.Now : dpEditTime.SelectedDate.Value;
                

                DataUpdate updata = new DataUpdate();
                string sql = "insert into T_SITE (SITE_ID,SITE_NAME,SITE_TITLE,SITE_DIR,SITE_ORDER,SITE_KEYS,SITE_NOTE,SITE_LOGO,SITE_PUBLISH,SITE_PUBLISH_TIME,SITE_LOG_CLEAR,SITE_UPLOAD_SIZE,SITE_ADD_TIME,SITE_UPDATE_TIME,SITE_UPLOAD_FILE_TYPE) values(‘" + txtSiteID.Text + "‘,‘" + txtSiteName.Text + "‘,‘" + txtSiteTitle.Text + "‘,‘" + txtSitePath.Text + "‘,‘" + txtSiteNumber.Text + "‘,‘" + txtKeyword.Text + "‘,‘" + txtWebDescription.Text + "‘,‘" + txtSiteLogo.Text + "‘,‘" + txtYesNORelease.Text + "‘,to_date(‘" +txtReleaseTime.SelectedDate.Value.ToString("yyyy-MM-dd hh:mm:ss") + "‘,‘YYYY-MM-DD hh24:mi:ss‘),‘" + txtDiaryEDay.Text + "‘,‘" + txtUpFileSize.Text + "‘,to_date(‘" +dpAddTime.SelectedDate.Value.ToString("yyyy-MM-dd hh:mm:ss") + "‘,‘YYYY-MM-DD hh24:mi:ss‘),to_date(‘" + time1.ToString("yyy-MM-dd hh:mm:ss") + "‘,‘YYYY-MM-DD hh24:mi:ss‘),‘" + txtUpFileTypeLimit.Text + "‘)";


                //insert语句太长,有StringBuilder优化一下
                StringBuilder sql1 = new StringBuilder();

                sql1.Append(@"insert into T_SITE (SITE_ID,SITE_NAME,SITE_TITLE,SITE_DIR,SITE_ORDER,SITE_KEYS,SITE_NOTE,SITE_LOGO,SITE_PUBLISH,SITE_PUBLISH_TIME,SITE_LOG_CLEAR,SITE_UPLOAD_SIZE,SITE_ADD_TIME,SITE_UPDATE_TIME,SITE_UPLOAD_FILE_TYPE) values(‘");
                sql1.Append(txtSiteID.Text); sql1.Append("‘,‘");
                sql1.Append(txtSiteName.Text); sql1.Append("‘,‘");
                sql1.Append(txtSiteTitle.Text); sql1.Append("‘,‘");
                sql1.Append(txtSitePath.Text); sql1.Append("‘,‘");
                sql1.Append(txtSiteNumber.Text); sql1.Append("‘,‘");
                sql1.Append(txtKeyword.Text); sql1.Append("‘,‘");
                sql1.Append(txtWebDescription.Text); sql1.Append("‘,‘");
                sql1.Append(txtSiteLogo.Text); sql1.Append("‘,‘");
                sql1.Append(txtYesNORelease.Text); 
                sql1.Append("‘,to_date(‘");
                sql1.Append(txtReleaseTime.SelectedDate.Value.ToString("yyyy-MM-dd hh:mm:ss"));
                sql1.Append("‘,‘YYYY-MM-DD hh24:mi:ss‘),‘");
                sql1.Append(txtDiaryEDay.Text); sql1.Append("‘,‘");
                sql1.Append(txtUpFileSize.Text);
                sql1.Append("‘,to_date(‘");
                sql1.Append(dpAddTime.SelectedDate.Value.ToString("yyyy-MM-dd hh:mm:ss"));
                sql1.Append("‘,‘YYYY-MM-DD hh24:mi:ss‘),to_date(‘");
                sql1.Append(time1.ToString("yyy-MM-dd hh:mm:ss"));
                sql1.Append("‘,‘YYYY-MM-DD hh24:mi:ss‘),‘");
                sql1.Append(txtUpFileTypeLimit.Text);
                sql1.Append("‘)");

                MessageBox.Show(sql1.ToString());
               
                updata.DataObjects.Add(sql1.ToString());
                
                updata.DataObjects.Add(sql);
                updata = m_IDataProvider.Execute(updata);
                if (updata.ExecuteState)
                {
                    MessageBox.Show("插入成功");
                }
            }
            else
            { 
                
            }
           
        }
    }
}


insert语句太长,有StringBuilder优化一下,布布扣,bubuko.com

insert语句太长,有StringBuilder优化一下

原文:http://blog.csdn.net/fanbin168/article/details/25376957

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!