我有gridview和
GridViewName.DataSource = table;
表值:
string myConnection = ConfigurationManager.ConnectionStrings["vizitka"].ToString();
string Query_sel = MySqlString;
MySqlConnection conDataBase = new MySqlConnection(myConnection);
MySqlCommand cmdDataBase_sel = new MySqlCommand(Query_sel, conDataBase);
try
{
MySqlDataAdapter sda = new MySqlDataAdapter();
sda.SelectCommand = cmdDataBase_sel;
DataTable dbdataset = new DataTable();
sda.Fill(dbdataset);
BindingSource bSource = new BindingSource();
bSource.DataSource = dbdataset;
TableName.DataSource = bSource;
sda.Update(dbdataset);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
我得到了价值观:
然后,我向表中添加新行:
DataRow newRow = table.NewRow();
table.Rows.Add(newRow);
以及使用空单元格获取值(id也是空的,这对我很好):
然后:
GridViewName.DataSource = table;
一切都很好,但如果我想从表中删除这个新创建的行,我不能。我正在尝试再次筛选和绑定gridviewname。
DataView view = new DataView(table);
view.RowFilter = "CONVERT(id, System.String) = null or CONVERT(id, System.String) = ''";
Console.WriteLine(view);
但我的table空了。为什么?
1条答案
按热度按时间tkclm6bt1#
我假设id是数字。您不希望=null,您希望是null,这是您在dataview(以及sql)中检查null的方式。