弱弱的问,怎样使用SqlCommandBuilder更新数据库
看看代码更新不了。。。
protected void ok_Click(object sender, EventArgs e)
{
string strConn = System.Configuration.ConfigurationManager.ConnectionStrings[ "jobmanageConnectionString "].ConnectionString;
SqlConnection Conn = new SqlConnection(strConn);
Conn.Open();
DataSet ds = new DataSet();
string strSql = "select * from jiuye where xuehao = ' " + name + " ' ";
SqlDataAdapter da = new SqlDataAdapter(strSql,Conn);
da.Fill(ds, "jiuye ");
SqlCommandBuilder cb = new SqlCommandBuilder (da);
DataTable dt = ds.Tables[ "jiuye "];
DataRow dr = dt.Rows[0];
dr[ "jiuyebiaozhiid "] = jybz.Text;
da.Update(ds, "jiuye ");
Conn.Close();
}
请指点 在线等答案,thx orz
[解决办法]
string strConn = System.Configuration.ConfigurationManager.ConnectionStrings[ "jobmanageConnectionString "].ConnectionString;
SqlConnection Conn = new SqlConnection(strConn);
Conn.Open();
string sql = "select * from jiuye where xuehao = ' " + name + " ' ";
SqlDataAdapter da = new SqlDataAdapter(sql,Conn);
SqlCommandBuilder cb = new SqlCommandBuilder(da);
DataSet ds = new DataSet();
da.Fill(ds, "jiuye ");
dt = ds.Tables[ "jiuye "];
dt.PrimaryKey = new DataColumn[]{dt.Columns[ "xuehao "],dt.Columns[ "danweiid "]};
int ids = Int32.Parse(this.某一主键列.Text);
DataRow dr = dt.Rows.Find(ids);//获取由主键值指定的行
dr[ "jiuyebiaozhiid "] = jybz.Text;//更新
da.Update(ds, "jiuye ");
Conn.Close();
俺自己感觉还是用SQL语句来得舒服些