VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > c#编程 >
  • C#教程之insert语句太长用StringBuilder优化一下

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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
      {  
          
      
        
    
  
}

 



相关教程