请问:这段代码 执行时会在“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>");
}
}
}
解决方案 »
- jquery 如何知道点击了哪个连接
- 请问,如何学习ADO.NET
- HELP!_vs2005 SP1发布网站时生成失败,没有错误信息,没有警告信息
- 多台服务器如何共享session与application?
- 怎么隐藏控件?
- ajax发布到2008 server失效问题!急求解
- Datagrid中绑定的文本框的内容是否修改后,数据库的信息也跟着改变?
- 如何通过jS获取动态创建的控件的clientID
- Web项目的管理问题
- “/asp.netwebadminfiles”应用程序中的服务器错误。
- 如何DataGridView在单元格的编辑事件中设置成Combobox??
- 关于vs2010类库的问题!(50分)
=》
StrSqls = "update t_intro set introduce='" + this.FreeTextBox1.Text + "' where introid = '1'";
一般提示xxx附近有语法错误,很大一部分情况是sql写的不对,把这条sql取出来仍数据库里试试就知道错哪了