2
votes

DataGridView1.DataSource = ds.Tables("Orders")

If the query returns no results (empty dataset table) I see -1 in first column of the DataGridView in OrderID column. When I click on a grid columns header it decreases -2, -3 etc.

How to fix it?

1

1 Answers

2
votes

How about:

If ds.Tables("Orders").Rows.Count = 0 Then
  lblNoResults.Visible = True
  DataGridView1.Visible = False
Else
  lblNoResults.Visible = False
  DataGridView1.DataSource = ds.Tables("Orders")
  'Anything else you need to do
  DataGridView1.Visible = True
End If

lblNoResults would be a label with text something like "No results found" that you would display instead of your DataGridView.

Basically, don't bind the datasource if there are no rows in it.

It might be that there are bugs in your other code causing your specific problem. If you want to show more of your code then it'll be easier to say what's going wrong.