Blob field from a Dataset in a datagrid

I have a blob field in my database that contains a large amount of string data and I need to bind that data to a datagrid
here is the code I am currently trying

        Dim MySQLConnection1 As MySqlConnection
        Dim MySQLDataAdapter1 As MySqlDataAdapter
        Dim MySQLSelectCommand1 As MySqlCommand
        Dim dsMine As DataSet
        MySQLConnection1 = New MySqlConnection()
        MySQLDataAdapter1 = New MySqlDataAdapter()
        MySQLSelectCommand1 = New MySqlCommand()

        MySQLConnection1.ConnectionString = "Server=Main;Database=Test;Uid=user;Pwd=password;"

        Try
            MySQLConnection1.Open()
            MySQLSelectCommand1.Connection = MySQLConnection1
            MySQLDataAdapter1.SelectCommand = MySQLSelectCommand1
            MySQLSelectCommand1.CommandText = "SELECT blobfield FROM table"
            dsMine = New DataSet()
            MySQLDataAdapter1.Fill(dsMine)
            DataGrid1.DataSource = dsMine
        Catch ex As Exception
            Debug.WriteLine(ex.Message)
        End Try


I know this is MySQL but it shouldnt matter where the dataset originates I need to take the data that is contained in the blob field and display it as a string in the Datagrid
If I insert a simple string into blobfield such as 'simplestring'
I cannot read that back, I get Byte.Array[] as the returned value no matter what is in the blob field data. Any help would be great, Thank you
LVL 1
davidtrinaAsked:
Who is Participating?
 
Bob LearnedConnect With a Mentor Commented:
You need to use table styles and declare an extended column type:

Public Class DataGridBlobColumn
  Inherits DataGridTextBoxColumn

  Public Sub New(ByVal table As DataTable)
    m_table = table
  End Sub

  Private m_table As DataTable

  Protected Overrides Function GetColumnValueAtRow(ByVal source As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer) As Object
    Return System.Text.Encoding.UTF8.GetString(m_table.Rows(rowNum)("blobField"))
  End Function

End Class

Example usage:
   Dim style As New DataGridTableStyle
   style.MappingName = dsMine.Tables(0).TableName

   Dim blobColumn As New DataGridBlobColumn(dsMine.Tables(0))
   blobColumn.MappingName = "blobField"
   blobColumn.HeadingText = "Heading"
   
   style.GridColumns.Add(blobColumn)

   Dim textColumn As New DataGridTextBoxColumn()
   textColumn.MappingName = "fname"
   textColumn.HeadingText = "First"

   style.GridColumns.Add(textColumn)

   textColumn = New DataGridTextBoxColumn()
   textColumn.MappingName = "lname"
   textColumn.HeadingText = "Last"

   style.GridColumns.Add(textColumn)

   Me.DataGrid1.TableStyles.Clear()
   Me.DataGrid1.TableStyles.Add(style)

Bob
0
 
Bob LearnedCommented:
One possibility:

  Dim table As DataTable = dsMine.Tables(0)
  Dim row As DataRow = table.Rows(0)
  Dim simpleString As String = System.Text.Encoding.Utf8.GetString(row("blobField"))

Bob
0
 
maralansCommented:
Class level:
     
    Dim ss As String = "SELECT blobfield FROM table"
    Dim cs As String = "Server=Main;Database=Test;Uid=user;Pwd=password;"
    Dim cn As New Odbc.OdbcConnection(cs)
    Dim da As New Odbc.OdbcDataAdapter(ss, cn)
    dim ds As New DataSet
     
Load event:
       
        da.Fill(ds, "table")
        datagrid1.DataSource = ds.Tables("table")
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
maralansCommented:
Sorry Bob, I didn't refresh.
0
 
davidtrinaAuthor Commented:
 Dim table As DataTable = dsMine.Tables(0)
  Dim row As DataRow = table.Rows(0)
  Dim simpleString As String = System.Text.Encoding.Utf8.GetString(row("blobField"))

This does give me the value of the blob however I need that value to be displayed in the datagrid
0
 
Bob LearnedCommented:
Ooh, tough one!!!   I missed the DataGrid comment.  

1) .NET version?
2) Are you applying table styles to the DataGrid?

Bob
0
 
davidtrinaAuthor Commented:
currently writing this in .NET 2003
but will be changing to 2005 in the next couple of months
0
 
davidtrinaAuthor Commented:
I can apply table styles if need be, currently I just apply one to make fields read only or not and change the null value
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.