This is working for me just fine. With if checks if dataset is empty or not. If so, return null value. But is the check of dataset right way or should i do some other way?
da2 = new SqlDataAdapter("SELECT project_id FROM project WHERE _small_project_id = '" + cb_small_project.SelectedValue + "' ORDER BY NEWID()", conn);
ds2 = new DataSet();
da2.Fill(ds2);
DataRow[] rowProject = dt2.Select();
if (ds2.Tables[0].Rows.Count == 0)
cmd.Parameters["@_project_id"].Value = guidNull;
else
cmd.Parameters["@_project_id"].Value = rowProject[0]["project_id"];
In my opinion the ‘right’ way is to check both: