0

I have gridview and

GridViewName.DataSource = table;

table values:

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);
}

I get Values: Datatable

then, I'm adding new row to table:

DataRow newRow = table.NewRow();
table.Rows.Add(newRow);

and getting values with empty cells (also ID is empty and it's good for me):

new Table

then:

GridViewName.DataSource = table;

all is good, but then if I want to delete from table this new created row, I cannot. I'm trying to filter and bind again GridViewName.

DataView view = new DataView(table);
view.RowFilter = "CONVERT(id, System.String) = null or CONVERT(id, System.String) = ''";
Console.WriteLine(view);

but I'm getting empty table. Why?

Aleks Andreev
  • 7,016
  • 8
  • 29
  • 37
  • Note that besides using `RowFilter`, [you can use LINQ on a `DataTable` by using the `.AsEnumerable()` extension method](https://stackoverflow.com/a/48338232/). – NightOwl888 Jan 20 '18 at 12:28

1 Answers1

1

I assume the ID is numeric. You don't want = null, you want IS NULL, which is how you check for nulls in both DataView (and also in SQL).

view.RowFilter = "ID IS NULL";
Ctznkane525
  • 7,297
  • 3
  • 16
  • 40