
从数据库中取出的内容放入freetextbox中显示 然后修改,更新数据库内容,请发源码 , 10
展开全部
//首先你至少得有两按钮吧,一个读数据,一个写数据
static string temp;//设一个全局变量来记录你更新的是哪个数据
protected void Page_Load(object sender, EventArgs e)
{
}
//这是读数据,写的比较简单,没有抓异常之类的。
protected void Button1_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
string strConn = "server=WANGCHUAN-PC.;uid=sa;pwd=123456;database=test";
SqlConnection con = new SqlConnection(strConn);
con.Open();
string sql = "select * from mytable";//注意你要使用的sql语句
SqlDataAdapter ad = new SqlDataAdapter(sql, strConn);
ad.Fill(ds);
con.Close();
Freetextbox1.Text = ds.Tables[0].Rows[0][0].ToString();//这要注意,你要读哪条数据,我的是第0行第0列
temp = Freetextbox1.Text;//给你的全局变量赋值
}
//这是更新数据
protected void Button2_Click(object sender, EventArgs e)
{
string strConn = "server=WANGCHUAN-PC.;uid=sa;pwd=123456;database=test";
SqlConnection con = new SqlConnection(strConn);
con.Open();
string sql = "update mytable set 姓名='" + Freetextbox1.Text + "' where 姓名='" + temp + "'";
SqlCommand com = new SqlCommand(sql, con);
com.ExecuteNonQuery();
con.Close();
}
static string temp;//设一个全局变量来记录你更新的是哪个数据
protected void Page_Load(object sender, EventArgs e)
{
}
//这是读数据,写的比较简单,没有抓异常之类的。
protected void Button1_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
string strConn = "server=WANGCHUAN-PC.;uid=sa;pwd=123456;database=test";
SqlConnection con = new SqlConnection(strConn);
con.Open();
string sql = "select * from mytable";//注意你要使用的sql语句
SqlDataAdapter ad = new SqlDataAdapter(sql, strConn);
ad.Fill(ds);
con.Close();
Freetextbox1.Text = ds.Tables[0].Rows[0][0].ToString();//这要注意,你要读哪条数据,我的是第0行第0列
temp = Freetextbox1.Text;//给你的全局变量赋值
}
//这是更新数据
protected void Button2_Click(object sender, EventArgs e)
{
string strConn = "server=WANGCHUAN-PC.;uid=sa;pwd=123456;database=test";
SqlConnection con = new SqlConnection(strConn);
con.Open();
string sql = "update mytable set 姓名='" + Freetextbox1.Text + "' where 姓名='" + temp + "'";
SqlCommand com = new SqlCommand(sql, con);
com.ExecuteNonQuery();
con.Close();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询