protected void Sub_button(object sender, EventArgs e)
{
if (Page.IsValid)
{
string strConn = "provider=SQLOLEDB;data source=(LOCAL);UID=SA;PWD=*** DATABASE=test";
OleDbConnection conn = new OleDbConnection(strConn);
conn.open();
string name, realname, sex,question, answer, email;
name = Session["username"].ToString();
realname = TextBox1.Text.Trim();
sex = RadioButtonList1.SelectedItem.Text.Trim();
question = DropDownList1.SelectedItem.Text;
answer = TextBox2.Text.Trim();
email = TextBox3.Text.Trim();
string sql = "select * from [user] where UserName='" + name + "'";
SqlCommand
command=new
SqlCommand(sql,connection);
//创建adapter
SqlDataAdapter adapter=new
SqlDataAdapter(sql,conn);
DataSet ds=new DataSet();
adapter.Fill(ds,"[user]");
ds.Rows[0]["realname"] = realname;
ds.Rows[0]["sex"]= sex;
ds.Rows[0]["question"] = question;
ds.Rows[0]["answer"]= answer;
ds.Rows[0]["email"]= email;
SqlCommandBuilder commandbuilder=new
SqlCommandBuilder(adapter);
adapter.UpdateCommand=commandbuilder.GetUpdateCommand();
adapter.Update(ds,"[user]");
Response.Redirect("main.aspx");
}
}