日期:2014-05-17  浏览次数:20438 次

sql字符串拼接问题
本帖最后由 llc961478 于 2013-11-05 09:37:08 编辑
    protected void lkupdzlxx_Click(object sender, EventArgs e)
    {
        try
        {
            sqlcon scn = new sqlcon();
            scn.con();
            scn.setinsert("治疗信息(ID, 治疗方式, 剂量, 计划, 实际, 开始时间, 结束时间,结束提醒)",
                "'" + txtid.Text + "'," + "'" + txt1zhiliaofangshi.Text + "'," + "'" + txt2jiliang.Text + "'," +
                "'" + txt3jihua.Text + "'," 
+ "'" + txt4shiji.Text + "'," +
                "'" + txt5starttime.Text + "'," +
 "'" + txt6endtime.Text + "'," +
                "'" + txt7remindtime.Text + "'");
            Response.Write("success");
        }
        catch { Response.Write("false"); }
    }


 public void setinsert(string columnname,string insertstring)
    {
       sda.InsertCommand = new SqlCommand( "insert into " + columnname + " values (" + insertstring + ")");
    }


断点调试后 sda中InsertCommand为:
"insert into 治疗信息(ID, 治疗方式, 剂量, 计划, 实际, 开始时间, 结束时间,结束提醒)
 values ('2','q','q','q','q','2013-11-5 09:31:16',
'2013-11-5 10:31:16','2013-11-5 10:26:16')"、
//此时数据库中无生成内容。
//将该语句复制到sql查询中得到1行影响,数据被添加


求帮助啊! 

------解决方案--------------------

------解决方案--------------------
看不出什么问题。。难道数据库里有插入触发器