Hi Member 9983063, the following line is not checking for an empty table.
if (dsa != null)
And it is never NULL as an object is assigned to it; a memory is allocated.
DataSet dsa = new DataSet();
So the conditional check is actually not checking for what you need.
What will be best is check the number of rows returned in the datatable.
da.Fill(dt);
if (dt.Rows.Count > 0)
{
textBox2.Text = dt.Rows[0]["Product Name"].ToString();
}
else
{
MessageBox.Show("Hello World", "Combobox1", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
The dataset is not used in this portion. If it is not used otherwise you can remove it.
Also mind the first point from OriginalGriff. This is very crucial not to send the query string over the network. For small scale intra-network applications this might be no problem, but for large-scale enterprise applications this is a very important trapdoor. So it is better to stand on the practice from the very beginning.