110,567
社区成员
发帖
与我相关
我的任务
分享
string name;
string job;
string monitor;
name = this.dgvInformation.CurrentRow.Cells[1].Value.ToString();
job = this.dgvInformation.CurrentRow.Cells[2].Value.ToString();
monitor = this.dgvInformation.CurrentRow.Cells[3].Value.ToString();
//con.InsertRow(name, job, monitor, txtCNm.Text);
con.Connecttion();//调用函数,能够连接数据库
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("select * from T_Class1", con.Con);//Con属性用来获取链接的sqlconnection对象
da.Fill(ds,tablename);
//DataTable table = ds.Tables[tablename];
DataRow row = ds.Tables[tablename].NewRow();
row["Name"] = name;
row["Job"] = job;
row["Monitor"] = monitor;
ds.Tables[name].Rows.Add(row);
dgvInformation.DataSource = ds.Tables;
SqlCommandBuilder builder = new SqlCommandBuilder(da);
da.Update(ds);