当前位置:主页 > 软件编程 > .NET代码 >

insert语句太长用StringBuilder优化一下

时间:2021-01-18 14:44:55 | 栏目:.NET代码 | 点击:

 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 
      {  
         
      } 
       
    } 
  } 
}

您可能感兴趣的文章:

相关文章