Error When Displaying Query In Dataview

Hello,

I have a datagridview which the user populates with whatever query they want to type which queries the database specified by their connection string.

It's working great with only one problem that I can tell.  If the user writes a query that contains an image field I get the following error message:

The following exception occured in the DataGridView:  

System.ArgumentException: Parameter is not valid.
  at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
 at System.Drawing.ImageConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
 at System.Windows.Forms.Formatter.FormatObjectInternal(Object value, Type targetType, TypeConverter sourceConverter, TypeConverter targetConverter, String formatString, IFormatProvider formatInfo, Object formattedNullValue)
 at System.Windows.Forms.Formatter.FormatObject(Object value, Type targetType, TypeConverter sourceConverter, TypeConverter targetconverter, String formatString, IFormatProvider formatInfo, Object formattedNullValue, Object dataSourceNullValue)
 at System.Windows.Forms.DataGridViewCell.GetFormattedValue(Object value, Int32 rowIndex, DataGridViewCellStyle& cellStyle, TypeConverter valueTypeConverter, TypeConverter formattedValueTypeConverter, DataGridVewDataErrorContexts context)

To replace this default dialog please handle the DataError event.

How can I prevent this error from occurring, or prevent the user from querying an Image field?

Thanks,
-Torrwin
LVL 13
TorrwinAsked:
Who is Participating?
 
RedKelvinCommented:
Hi,
Take a look at this, it deals with storing and retrieving images
http://articles.techrepublic.com.com/5100-3513-5766889.html

Or you could check the column datatypes like this
http://www.java2s.com/Code/VB/Database-ADO.net/GetColunmDatatype.htm

RedK
0
 
TorrwinAuthor Commented:
Thanks for putting me on the right track at least.  Here's how I did it:

With dsTemp.Tables(0)
     For i As Integer = 0 To dsTemp.Tables(0).Columns.Count - 1
          If InStr(.Columns(i).DataType.ToString, GetType(Byte).ToString) > 0 Then
               dsTemp.Tables(0).Columns(i).ColumnMapping = MappingType.Hidden
          End If
     Next
End With

DataGridView1.DataSource = dsTemp.Tables(0)

Where dsTemp is the dataset with your query results.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.