Q: Try catch never enters catch block The problem with the code below is that I never see my catch code execute. If my id doesn't exist, it shows a empty datagrid. What goes wrong?
private void btnSearch_Click(object sender, EventArgs e)
{
    try
    {
        this.Cursor = Cursors.WaitCursor;
        SqlConnectie vandaag = new SqlConnectie();
        vandaag.Connection();
        SqlDataAdapter sda = new SqlDataAdapter("select ID, VERSIE, SB, NAAM, M_DATUM, V_DATUM from RE1 where ID=" + tbRecept.Text, SqlConnectie.conn);
        DataTable dt = new DataTable();
        sda.Fill(dt);
        dgvTemp.DataSource = dt;
        SqlConnectie.conn.Close();
        this.Cursor = Cursors.Default;
    }

    catch
    {
        MessageBox.Show("ID doesn't exist");
    }
}


A: Why do you expect an exception if no row is returned from database? It is perfectly valid to get an empty resultset, the dataadapter will return an empty DataTable.
You could check it:
DataTable dt = new DataTable();
sda.Fill(dt);
dgvTemp.DataSource = dt;
if(dt.Rows.Count == 0)
    MessageBox.Show("ID doesn't exist");

