public Boolean ExecSql(string sQueryString)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["conStr"]);
        
        SqlCommand command1 = new SqlCommand(sQueryString, con);
        command1.Connection.Open();
        command1.ExecuteNonQuery();
        command1.Connection.Close();
        return true;
    }
然后我在一个buttion的OnClick事件中写到
{
bc.ExecSql("Update News SET Title=" + "'" + TextBox1.Text + "'");
}
运行后没有发生改变,页面就只是刷新了一下而已.这是怎么回事?

解决方案 »

  1.   

    <asp:button>里 是否有 onclick="button1_OnClick"
    检查下
      

  2.   

    bc.ExecSql("Update News SET Title=" + "'" + TextBox1.Text + "'");tobc.ExecSql("Update News SET Title= "' + TextBox1.Text + "'");
      

  3.   

    楼上所写,我早已经试过了.另外我发现我用:"Update News SET Title=111"也就是设为常量可以,后来我通过输出文本的方式看看具体语句,发现只要加上单引号,就不行.
      

  4.   

    bc.ExecSql("Update News SET Title=" + "'" + TextBox1.Text + "'");tobc.ExecSql(String.Format("Update News SET Title='{0}' ", TextBox1.Text );
      

  5.   

    ExecSql 这个方法〉。
    呵呵;楼主还是改改吧
      

  6.   

    建议你单步调试下,首先看看参数是否传递进去,其次看看是否执行了sql语句
      

  7.   

    public Boolean ExecSql(string sQueryString)
        {
    try
    {
            SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["conStr"]);
            
            SqlCommand command1 = new SqlCommand(sQueryString, con);
            command1.Connection.Open();
            command1.ExecuteNonQuery();
            command1.Connection.Close();
    }catch(Exception ex)
    {
     Response.Write(ex.Message)
    }
            return true;
        }用try...catch试下
      

  8.   

    换常量会执行,但是一遇'号就不行了.比如:Title=222222这样就可以.我有进行输出,发现加了'就输出不了.也不报错,就是刷新了一下.