?
Solved

Blob field from a Dataset in a datagrid

Posted on 2006-05-08
8
Medium Priority
?
338 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:davidtrina
  • 3
  • 3
  • 2
8 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16635845
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
 
LVL 5

Expert Comment

by:maralans
ID: 16635902
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
 
LVL 5

Expert Comment

by:maralans
ID: 16635906
Sorry Bob, I didn't refresh.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:davidtrina
ID: 16636176
 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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16639061
Ooh, tough one!!!   I missed the DataGrid comment.  

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

Bob
0
 
LVL 1

Author Comment

by:davidtrina
ID: 16641783
currently writing this in .NET 2003
but will be changing to 2005 in the next couple of months
0
 
LVL 1

Author Comment

by:davidtrina
ID: 16641792
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
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 16641985
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question