protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["id"] != null)
{ Panel1.Visible = true;
read_hotel();
}
} protected void Button1_Click(object sender, EventArgs e)
{
mod_hotel(); }
public void mod_hotel()//修改酒店
{ bool boolup = cbx_up.Checked;
int UP = boolup == true ? 1 : 0;
int STAR = int.Parse(dwl_star.Text.ToString());
string setting = Convert.ToString(ConfigurationManager.ConnectionStrings["sql"]);
SqlConnection myconn = new SqlConnection(setting);
myconn.Open();
SqlCommand mycmd = new SqlCommand("mod_hotel", myconn);
mycmd.CommandType = CommandType.StoredProcedure;
SqlParameter id = mycmd.Parameters.Add("@ID", SqlDbType.Int);
id.Value =int.Parse(Request.QueryString["id"].ToString());
SqlParameter name = mycmd.Parameters.Add("@name", SqlDbType.NVarChar, 20);
name.Value = tbx_name.Text.ToString();
SqlParameter rooms = mycmd.Parameters.Add("@rooms", SqlDbType.NVarChar, -1);
restaurant.Value = we_res.Text.ToString();
SqlParameter tel = mycmd.Parameters.Add("@tel", SqlDbType.NVarChar, 30);
tel.Value = tbx_tel.Text.ToString();
SqlParameter fax = mycmd.Parameters.Add("@fax", SqlDbType.NVarChar, 30);
fax.Value = tbx_fax.Text.ToString();
mycmd.ExecuteNonQuery();
myconn.Close();
Response.Write("<script>alert(\"修改成功\");window.location.href('hotel.aspx')</script>");
}
public void read_hotel()
{
string settings = Convert.ToString(ConfigurationManager.ConnectionStrings["Sql"]);
SqlConnection myconn1 = new SqlConnection(settings);
myconn1.Open();
string strsql = "select * from hotel where ID=" + Request.QueryString["id"].ToString();
SqlCommand mycmd2 = new SqlCommand(strsql, myconn1);
SqlDataReader dr = mycmd2.ExecuteReader();
if (dr.Read())
{
tbx_name.Text = dr["Name"].ToString();
tbx_fax.Text = dr["fax"].ToString();
tbx_tel.Text = dr["tel"].ToString();
we_rooms.Text = dr["rooms"].ToString(); }
else
{
Response.Write("读取错误,请重试");
}
dr.Close();
}}
可以读取出来,我点确定按钮以后写不进数据库,是怎么回事 高手帮帮忙,有什么不详细的就说说 或者加我Q 392240196
{
if (Request.QueryString["id"] != null)
{ Panel1.Visible = true;
read_hotel();
}
} protected void Button1_Click(object sender, EventArgs e)
{
mod_hotel(); }
public void mod_hotel()//修改酒店
{ bool boolup = cbx_up.Checked;
int UP = boolup == true ? 1 : 0;
int STAR = int.Parse(dwl_star.Text.ToString());
string setting = Convert.ToString(ConfigurationManager.ConnectionStrings["sql"]);
SqlConnection myconn = new SqlConnection(setting);
myconn.Open();
SqlCommand mycmd = new SqlCommand("mod_hotel", myconn);
mycmd.CommandType = CommandType.StoredProcedure;
SqlParameter id = mycmd.Parameters.Add("@ID", SqlDbType.Int);
id.Value =int.Parse(Request.QueryString["id"].ToString());
SqlParameter name = mycmd.Parameters.Add("@name", SqlDbType.NVarChar, 20);
name.Value = tbx_name.Text.ToString();
SqlParameter rooms = mycmd.Parameters.Add("@rooms", SqlDbType.NVarChar, -1);
restaurant.Value = we_res.Text.ToString();
SqlParameter tel = mycmd.Parameters.Add("@tel", SqlDbType.NVarChar, 30);
tel.Value = tbx_tel.Text.ToString();
SqlParameter fax = mycmd.Parameters.Add("@fax", SqlDbType.NVarChar, 30);
fax.Value = tbx_fax.Text.ToString();
mycmd.ExecuteNonQuery();
myconn.Close();
Response.Write("<script>alert(\"修改成功\");window.location.href('hotel.aspx')</script>");
}
public void read_hotel()
{
string settings = Convert.ToString(ConfigurationManager.ConnectionStrings["Sql"]);
SqlConnection myconn1 = new SqlConnection(settings);
myconn1.Open();
string strsql = "select * from hotel where ID=" + Request.QueryString["id"].ToString();
SqlCommand mycmd2 = new SqlCommand(strsql, myconn1);
SqlDataReader dr = mycmd2.ExecuteReader();
if (dr.Read())
{
tbx_name.Text = dr["Name"].ToString();
tbx_fax.Text = dr["fax"].ToString();
tbx_tel.Text = dr["tel"].ToString();
we_rooms.Text = dr["rooms"].ToString(); }
else
{
Response.Write("读取错误,请重试");
}
dr.Close();
}}
可以读取出来,我点确定按钮以后写不进数据库,是怎么回事 高手帮帮忙,有什么不详细的就说说 或者加我Q 392240196
if (!IsPostBack)
{
}
才能修改,否则得到的还是原来数据
protected void Page_Load(object sender, EventArgs e)
{ if(!isPostBack)
{
if (Request.QueryString["id"] != null)
{ Panel1.Visible = true;
read_hotel();
}
}
}
楼上正解 , 每次按button 都要先执行Page_Load ,你每次都执行 read_hotel(); 函数 数据进去了就和以前一样