insert语句太长用StringBuilder优化一下
程序员文章站
2024-02-21 12:54:22
private void btnsave_click(object sender, routedeventargs e)
{
if (...
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 { } } } }