string sqlConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
int typeid = int.Parse(Request["id"].ToString());
using (SqlConnection con = new SqlConnection(sqlConnString))
{
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = "Select * from type where typeid=" + typeid;
con.Open();
SqlDataReader ds = cmd.ExecuteReader();
if (ds.Read())
{
TextBox1.Text = ds["type"].ToString();
txtTitle.Text = ds["note"].ToString();
}
ds.Close();
con.Close();
}
}
protected void Button2_Click(object sender, ImageClickEventArgs e)
{
int typeid = int.Parse(Request["id"].ToString());
SqlConnection con = new SqlConnection(sqlConnString);
SqlCommand cmd1 = con.CreateCommand();
string type = this.TextBox1.Text;
string note = this.txtTitle.Text;
cmd1.CommandText = "update type set type='"+type+"',note='"+note+"' where typeid=" + typeid;
con.Open();
int sdr = cmd1.ExecuteNonQuery();
if (sdr == 0)
{
ScriptManager.RegisterStartupScript(Button2, this.GetType(), "Button2", "alert('更新大类失败!');", true);
} else
{
ScriptManager.RegisterStartupScript(Button2, this.GetType(), "Button2", "alert('更新大类成功!');", true);
this.TextBox1.Text = string.Empty;
this.txtTitle.Text = string.Empty;
}
con.Close();
}
不知道是不是少了什么关键的东西,我更新是成功的,但是数据不变,断点cmd1.CommandText = "update type set type='"+type+"',note='"+note+"' where typeid=" + typeid;
commandText="" 请高手看看我哪里搞错了
protected void Page_Load(object sender, EventArgs e)
{
int typeid = int.Parse(Request["id"].ToString());
using (SqlConnection con = new SqlConnection(sqlConnString))
{
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = "Select * from type where typeid=" + typeid;
con.Open();
SqlDataReader ds = cmd.ExecuteReader();
if (ds.Read())
{
TextBox1.Text = ds["type"].ToString();
txtTitle.Text = ds["note"].ToString();
}
ds.Close();
con.Close();
}
}
protected void Button2_Click(object sender, ImageClickEventArgs e)
{
int typeid = int.Parse(Request["id"].ToString());
SqlConnection con = new SqlConnection(sqlConnString);
SqlCommand cmd1 = con.CreateCommand();
string type = this.TextBox1.Text;
string note = this.txtTitle.Text;
cmd1.CommandText = "update type set type='"+type+"',note='"+note+"' where typeid=" + typeid;
con.Open();
int sdr = cmd1.ExecuteNonQuery();
if (sdr == 0)
{
ScriptManager.RegisterStartupScript(Button2, this.GetType(), "Button2", "alert('更新大类失败!');", true);
} else
{
ScriptManager.RegisterStartupScript(Button2, this.GetType(), "Button2", "alert('更新大类成功!');", true);
this.TextBox1.Text = string.Empty;
this.txtTitle.Text = string.Empty;
}
con.Close();
}
不知道是不是少了什么关键的东西,我更新是成功的,但是数据不变,断点cmd1.CommandText = "update type set type='"+type+"',note='"+note+"' where typeid=" + typeid;
commandText="" 请高手看看我哪里搞错了
你有没有放复制到数据库中试试啊?我试了试,type是关键字,列名和表名相同不会冲突吧!
你这样
cmd1.CommandText = "update type set type='"+type+"',note='"+note+"' where typeid=" + typeid;
在这一句打上断点。。 看看拼接的SQL语句是否正确 然后将SQL语句复制到数据库去跑 再具体分析一下