日期:2014-05-18 浏览次数:20441 次
//读取数据库 string strSql = "select * from student where stuid = '001'"; DataTable dt = SqlHelper.GetDateTable(strSql,CommandType.Text); if(dt.Rows.Count>0) { txtName.Text = dt.Rows[0]["Name"].ToString(); txtAge.Text = dt.Rows[0]["Age"].ToString(); ...... } //更新数据库 string strUpdate = "update student set name='"+txtName.Text.Trim()+"',age='"txtAge.Text.Trim()+"',xxx='"+...略..Text.Trim()+"'"; int result = SqlHelper.ExecuteNonQuery(strUpdate); if(result>0) MessageBox.Show("更新成功"); else MessageBox.Show("更新失败");
------解决方案--------------------
void DateTocontrol(DataTable dt) { txt_MemName.Text= dt.Rows[0][1].ToString(); txt_BirthDate.Text = (DateTime.Parse( dt.Rows[0][2].ToString()) ).ToString("yyyy-MM-dd"); txt_民族.SelectedValue = dt.Rows[0][4].ToString(); txt_职称.SelectedValue = dt.Rows[0][5].ToString(); txt_学位.SelectedValue = dt.Rows[0][7].ToString(); txt_学校.SelectedValue = dt.Rows[0][6].ToString(); string 主要成果= dt.Rows[0][14].ToString(); string[] cg = 主要成果.Split('^'); if (cg.Length > 0) { for (int i = 0; i < cg.Length; i++) { foreach (Control control in this.Form.Controls) { if (control is System.Web.UI.WebControls.TextBox) { TextBox txt = (TextBox)control; if (txt.ID == "TextBox" + i) { txt.Text = cg[i].ToString(); } } } } } TextBox研究方向.Text = dt.Rows[0][8].ToString(); hide.Value = dt.Rows[0][16].ToString(); txt_工作单位.Text = dt.Rows[0][9].ToString(); txt_兼职.Text = dt.Rows[0][10].ToString(); txt_TEL.Text = dt.Rows[0][11].ToString(); txt_QQ.Text= dt.Rows[0][12].ToString(); txt_EMAIL.Text = dt.Rows[0][13].ToString(); // txt_成果.Text = dt.Rows[0][14].ToString(); txt_memo.Text = dt.Rows[0][15].ToString(); }