请问:这段代码 执行时会在“cmd1.ExecuteNonQuery();//执行修改数据信息的操作”提示“在逗号附近有语法错误”,是怎么回事呢?纠结了半天没有找到原因 很急呀 public partial class Manage_AdminIntro : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ try
{
if (!IsPostBack)
{
Button2.Attributes.Add("onclick", "return confirm('您确定要修改该信息吗?')");
SqlConnection sqlcon = new SqlConnection(ConfigurationManager.ConnectionStrings["connection"].ConnectionString);
sqlcon.Open();
string strselect = "select * from t_intro where introid = '1'";
SqlCommand cmd = new SqlCommand(strselect, sqlcon);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
FreeTextBox1.Text = dr["introduce"].ToString();
}
dr.Close();
sqlcon.Close(); }
}
catch{}
}
protected void Button2_Click(object sender, EventArgs e)
{
//不正确
if (FreeTextBox1.Text == "")
{
Response.Write("<script>alert('简介内容不能为空!')</script>");
return; //返回操作
}
else
{
SqlConnection sqlcon1 = new SqlConnection(ConfigurationManager.ConnectionStrings["connection"].ConnectionString);
sqlcon1.Open();
string StrSqls = "";
StrSqls = "update t_intro set introduce=" + this.FreeTextBox1.Text + "where introid = '1'";
SqlCommand cmd1 = new SqlCommand(StrSqls,sqlcon1);
cmd1.ExecuteNonQuery();//执行修改数据信息的操作
sqlcon1.Close(); //关闭数据库连接
Response.Write("<script>alert('简介编辑成功!')</script>");
}
}
}
{
protected void Page_Load(object sender, EventArgs e)
{ try
{
if (!IsPostBack)
{
Button2.Attributes.Add("onclick", "return confirm('您确定要修改该信息吗?')");
SqlConnection sqlcon = new SqlConnection(ConfigurationManager.ConnectionStrings["connection"].ConnectionString);
sqlcon.Open();
string strselect = "select * from t_intro where introid = '1'";
SqlCommand cmd = new SqlCommand(strselect, sqlcon);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
FreeTextBox1.Text = dr["introduce"].ToString();
}
dr.Close();
sqlcon.Close(); }
}
catch{}
}
protected void Button2_Click(object sender, EventArgs e)
{
//不正确
if (FreeTextBox1.Text == "")
{
Response.Write("<script>alert('简介内容不能为空!')</script>");
return; //返回操作
}
else
{
SqlConnection sqlcon1 = new SqlConnection(ConfigurationManager.ConnectionStrings["connection"].ConnectionString);
sqlcon1.Open();
string StrSqls = "";
StrSqls = "update t_intro set introduce=" + this.FreeTextBox1.Text + "where introid = '1'";
SqlCommand cmd1 = new SqlCommand(StrSqls,sqlcon1);
cmd1.ExecuteNonQuery();//执行修改数据信息的操作
sqlcon1.Close(); //关闭数据库连接
Response.Write("<script>alert('简介编辑成功!')</script>");
}
}
}
=》
StrSqls = "update t_intro set introduce='" + this.FreeTextBox1.Text + "' where introid = '1'";
一般提示xxx附近有语法错误,很大一部分情况是sql写的不对,把这条sql取出来仍数据库里试试就知道错哪了