这是代码:
BindingSource bs = new BindingSource();
DataTable tbl(string sql)
{
OracleConnection con = new OracleConnection(connectionstring);
OracleDataAdapter adp = new OracleDataAdapter(sql, con);
DataSet ds = new DataSet();
adp.Fill(ds, "tbl");
return ds.Tables["tbl"];
}
void GetData()
{
bs.DataSource = Class1.tbl("select USER_ID ,EMP_NAME as pName,EMP_MOBILE from TBLUSERS");
datagridview1.Columns[0].DataPropertyName = "USER_ID";
datagridview1.Columns[1].DataPropertyName = "pName";
datagridview1.Columns[2].DataPropertyName = "EMP_MOBILE";
datagridview1.DataSource = bs;
}
void ClearAllRows()
{
datagridview1.Rows.Clear();
//The error occurs here
}
错误发生在这里如何删除 DataGridView 的所有行?我的 DataGridView 是 BindingSource