dataset怎么删除指定行 5
privatevoid确定删除_Click(objectsender,EventArgse){SqlConnectionconn=newSqlConnection("Da...
private void 确定删除_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=学生管理;Integrated Security=True;");
SqlDataAdapter adapter = new SqlDataAdapter("Select * from xsxx", conn);
SqlCommand con = new SqlCommand("Select *from xxxx", conn);
// DataSet dataset = new DataSet();
学生管理DataSet dataset = new 学生管理DataSet();
conn.Open();
for (int i = 0; i < dataset.xsxx.Rows.Count - 1; i++)
{
if (dataset.xsxx.Rows[i]["学号"].ToString() == SNO.Text)
{
//dataset.xsxx.Rows.Remove(dataset.xsxx .Rows [i]);
dataset.xsxx.Rows[i].Delete();
SqlCommandBuilder cb = new SqlCommandBuilder(adapter);
adapter.Update(dataset.xsxx);
adapter.Fill(dataset.xsxx);
}
}
MessageBox.Show("删除成功");
// dataGridView1.DataSource = dataset.xsxx;
}
} 展开
{
SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=学生管理;Integrated Security=True;");
SqlDataAdapter adapter = new SqlDataAdapter("Select * from xsxx", conn);
SqlCommand con = new SqlCommand("Select *from xxxx", conn);
// DataSet dataset = new DataSet();
学生管理DataSet dataset = new 学生管理DataSet();
conn.Open();
for (int i = 0; i < dataset.xsxx.Rows.Count - 1; i++)
{
if (dataset.xsxx.Rows[i]["学号"].ToString() == SNO.Text)
{
//dataset.xsxx.Rows.Remove(dataset.xsxx .Rows [i]);
dataset.xsxx.Rows[i].Delete();
SqlCommandBuilder cb = new SqlCommandBuilder(adapter);
adapter.Update(dataset.xsxx);
adapter.Fill(dataset.xsxx);
}
}
MessageBox.Show("删除成功");
// dataGridView1.DataSource = dataset.xsxx;
}
} 展开
3个回答
推荐于2016-03-02 · 知道合伙人数码行家
关注
展开全部
和DataGrid 绑定了 可以这样处理
CurrencyManager cm = this.BindingContext[grdList.DataSource, grdList.DataMember] as CurrencyManager;
DataRowView drv = cm.Current as DataRowView;
drv 就是获得的当前行,例如如果该行中有ID
string id = drv["id"].ToString();
如果删除 直接可以调用drv.Delete();就可以删除当前行。
CurrencyManager cm = this.BindingContext[grdList.DataSource, grdList.DataMember] as CurrencyManager;
DataRowView drv = cm.Current as DataRowView;
drv 就是获得的当前行,例如如果该行中有ID
string id = drv["id"].ToString();
如果删除 直接可以调用drv.Delete();就可以删除当前行。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询