try
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ETHANConnectionString"].ConnectionString);
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
conn.Open(); string sqlwr = "update EMPBaseInfo set EMPName='" + TextBox2.Text.Trim() + "' where EMPID= 'ET-00002'";
SqlCommand cmd = new SqlCommand(sqlwr, conn);
cmd.ExecuteNonQuery();
cmd.Dispose();
conn.Close();
Response.Write("<script>alert('保存成功!')</script>");
}
catch
{
Response.Write("<script>alert('error!')</script>");
}更新不了 没有报错 也没有catch error
郁闷啊难道还有权限的问题?
能insert 应该不至于权限问题吧
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ETHANConnectionString"].ConnectionString);
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
conn.Open(); string sqlwr = "update EMPBaseInfo set EMPName='" + TextBox2.Text.Trim() + "' where EMPID= 'ET-00002'";
SqlCommand cmd = new SqlCommand(sqlwr, conn);
cmd.ExecuteNonQuery();
cmd.Dispose();
conn.Close();
Response.Write("<script>alert('保存成功!')</script>");
}
catch
{
Response.Write("<script>alert('error!')</script>");
}更新不了 没有报错 也没有catch error
郁闷啊难道还有权限的问题?
能insert 应该不至于权限问题吧
textbox数值也是通过ET-00002获取的 再修改的
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ETHANConnectionString"].ConnectionString);
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
conn.Open(); string sqlwr = "update EMPBaseInfo set EMPName='" + TextBox2.Text.Trim() + "' where EMPID= 'ET-00002'";
SqlCommand cmd = new SqlCommand(sqlwr, conn);
bool flag = cmd.ExecuteNonQuery() > 0 ? true : false;
cmd.Dispose();
conn.Close();
if (flag)
{
Response.Write("<script>alert('保存成功!')</script>");
}
}
catch
{
Response.Write("<script>alert('error!')</script>");
}
看它还弹不弹 了
原来是前面Page_Load里
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ETHANConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "select EMPName from [EMPBaseInfo] where EMPID='ET-00002'";
string rstNM = string.Empty;
conn.Open();
using (SqlDataReader reader = cmd.ExecuteReader())
{
if (reader.Read())
{
rstNM = Convert.ToString(reader["EMPName"]);
}
}
conn.Close();
TextBox2.Text = rstNM;
获取了 sql信息,
到后面 button3 click事件里
try
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ETHANConnectionString"].ConnectionString);
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
conn.Open(); string sqlwr = "update EMPBaseInfo set EMPName='" + TextBox2.Text.Trim() + "' where EMPID= 'ET-00002'";
SqlCommand cmd = new SqlCommand(sqlwr, conn);
bool flag = cmd.ExecuteNonQuery() > 0 ? true : false;
cmd.Dispose();
conn.Close();
if (flag)
{
Response.Write("<script>alert('保存成功!')</script>");
}
}
catch
{
Response.Write("<script>alert('error!')</script>");
}
就不能更改,
把前面那段page_load 里面 代码屏蔽掉 就可以更改了
这为什么?
获取信息之后 应是在内存里的噢 更改获取以后的数值 怎么就更改不了
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//你的代码
}
}
catch
{
Response.Write("<script>alert('error!')</script>");
}去掉后,就会报错了,把它去掉后再调试
好了,再加上,不然很难调试,不知那里错了
所以你在pageload中又重新给textbox赋值了。
请先认真了解下事件的执行顺序
if(!IsPostBack)
{
}
里面去