I agreed with Rohit that the root cause of your problem is the DBNull - as your error message clearly states.
When you run this query in SSMS it handles the display of the null itself, so you never have to worry about it. But when you code it, you have to handle the return value yourself, and DBNull is a specific value which does not work "nicely" with .NET. I woudl hcange hwat Rohit suggests slightly:
while (cla_filenames_dr.Read())
{
object o = cla_fileName_dr[0];
if (o != DBNull.Value)
{
MessageBox.Show((string) o);
}
In addition I would strongly recommend that you use a
using
block on your reader:
SqlCeCommand cla_filenames = new SqlCeCommand("SELECT MIN(file_name) FROM waveform_files WHERE file_name LIKE ' %" + cla + "% ' ", conn);
cla_filenames.CommandType = CommandType.Text;
using (SqlCeDataReader cla_filenames_dr = cla_filenames.ExecuteReader())
{
while (cla_filenames_dr.Read())
{
object o = cla_fileName_dr[0];
if (o != DBNull.Value)
{
MessageBox.Show((string) o);
}
}
}
Or you may find you have problems as the number of items in cc_list_array increases.