2 yang8ge yang8ge 于 2014.09.10 16:20 提问

c# text的内容修改后更新不成功

首先rowview一串数据库里的值,显示在textbox里面。然后在网页上修改textbox的值,然后将改后的值更新到数据库。
从数据库中取值
protected void Page_Load(object sender, EventArgs e)
{
ID = Request.QueryString["id"].ToString();
if (Session["loginName"] == null)
{
Response.Write("alert('请登录');location='../login.aspx'");
}
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["conStr"]);
con.Open();
SqlDataAdapter sda = new SqlDataAdapter("select * from news where ID=" + Request.QueryString["id"], con);
DataSet ds = new DataSet();
sda.Fill(ds, "news");
DataRowView rowview = ds.Tables["news"].DefaultView[0];
TextBox4.Text = rowview["title"].ToString();
TextBox3.Text = rowview["content"].ToString();
TextBox5.Text = rowview["picture"].ToString();
ds.Clear();
con.Close();
}
更新:
protected void Button1_Click(object sender, EventArgs e)
{
string filename = FileUpload2.FileName;
if (filename == "")
{
bc.ExecSQL("UPDATE news SET title = '" + this.TextBox4.Text + " ',submitDate='" + System.DateTime.Now.ToString("yyyyMMddHHmmss") + "', content = '" + this.TextBox3.Text + "', picture='" + this.TextBox5.Text + "',attachment=''where ID='" + ID + "'");
}
else
{
bc.ExecSQL("UPDATE news SET title = '" + this.TextBox4.Text + " ',submitDate='" + System.DateTime.Now.ToString("yyyyMMddHHmmss") + "', content = '" + TextBox3.Text + "', picture='" + TextBox5.Text + "',attachment='" + DateTime.Now.ToString("yyyyMMddHHmmss") + filename + "'where ID='" + ID + "'");
}
Response.Write(bc.MessageBox("数据修改成功!"));

1个回答

u013206003
u013206003   2015.08.18 09:14

if(!IsPostBack) 回传不加载数据库数据

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!