public void xiugai_click(object sender, EventArgs e)
{
string ID = Convert.ToString(Request["ID"]);
SqlConnection mycon = comy_user_editor_info_list.Getconn();
SqlCommand mycom = new SqlCommand();
mycom.Connection = mycon;
mycom.Parameters.AddWithValue("title", this.title.Text);
mycom.Parameters.AddWithValue("content", this.content.Value);
mycom.CommandText = "update Company set Company_Info_title='"+this.title.Text +"',Company_Info_content='"+this.content.Value+"' where ID='" + ID + "'";
DataSet myds = new DataSet();
SqlDataAdapter myda = new SqlDataAdapter(mycom);
myda.Fill(myds);
mycon.Open();
mycom.ExecuteNonQuery();
Response.Redirect("~/comy_user/my_info_list.aspx");
}
上面的不更新数据表怎么回事。。
将这句mycom.CommandText = "update Company set Company_Info_title='"+this.title.Text +"',Company_Info_content='"+this.content.Value+"' where ID='" + ID + "'";
这句改为mycom.CommandText = "update Company set Company_Info_title="+this.title.Text +",Company_Info_content="+this.content.Value+" where ID='" + ID + "'";出错,出错行为myda.Fill(myds);
出错内容是:
数字 名称 'System.Web.UI.WebControls' 包含的前缀数目超过了最大值。最大值为 3。
{
string ID = Convert.ToString(Request["ID"]);
SqlConnection mycon = comy_user_editor_info_list.Getconn();
SqlCommand mycom = new SqlCommand();
mycom.Connection = mycon;
mycom.Parameters.AddWithValue("title", this.title.Text);
mycom.Parameters.AddWithValue("content", this.content.Value);
mycom.CommandText = "update Company set Company_Info_title='"+this.title.Text +"',Company_Info_content='"+this.content.Value+"' where ID='" + ID + "'";
DataSet myds = new DataSet();
SqlDataAdapter myda = new SqlDataAdapter(mycom);
myda.Fill(myds);
mycon.Open();
mycom.ExecuteNonQuery();
Response.Redirect("~/comy_user/my_info_list.aspx");
}
上面的不更新数据表怎么回事。。
将这句mycom.CommandText = "update Company set Company_Info_title='"+this.title.Text +"',Company_Info_content='"+this.content.Value+"' where ID='" + ID + "'";
这句改为mycom.CommandText = "update Company set Company_Info_title="+this.title.Text +",Company_Info_content="+this.content.Value+" where ID='" + ID + "'";出错,出错行为myda.Fill(myds);
出错内容是:
数字 名称 'System.Web.UI.WebControls' 包含的前缀数目超过了最大值。最大值为 3。
SqlDataAdapter myda = new SqlDataAdapter(mycom);
myda.Fill(myds);
去掉试试。不行就输出sql语句在查询分析器里面执行下。
为填充dataset的语句。update只能返回受影响的行数。
把DataSet myds = new DataSet();
SqlDataAdapter myda = new SqlDataAdapter(mycom);
myda.Fill(myds);
这三行去掉。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: 第 1 行: '=' 附近有语法错误。源错误:
行 47: //myda.Fill(myds);
行 48: mycon.Open();
行 49: mycom.ExecuteNonQuery();
行 50: Response.Redirect("~/comy_user/my_info_list.aspx");
行 51: }
这行错误。。