Results 1 to 3 of 3

Thread: [RESOLVED] Fill a dataset from a SQL table with a binary field.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2004
    Posts
    95

    [RESOLVED] Fill a dataset from a SQL table with a binary field.

    How can I do this? It gives me an error saying: Inconvertable type mismatch between SourceColumn 'Hash' of Byte[] and the DataColumn 'Hash' of String.

    KT
    Last edited by Kt3; May 14th, 2004 at 08:07 AM.

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Try converting the byte array to a string

    VB Code:
    1. Dim bytByte() As Byte, strString As String
    2.         Dim myEncoding As New System.Text.ASCIIEncoding()
    3.         strString = myEncoding.GetString(bytByte)
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2004
    Posts
    95
    I used the sql datareader instead and created a new field entry for each column in an added row. Casting the binary field data as a byte() array type worked fine! In any case, I really appreciate you replying with a suggestion.. You da man..




    KT
    VB Code:
    1. Public Sub GetSubmitted(ByVal dataset As DataSet)
    2.  
    3.         Dim con As New SqlConnection(ConnectionString)
    4.         Dim cmd As New SqlCommand("GetSubmitted", con)
    5.         Dim param As SqlParameter
    6.  
    7.         cmd.CommandType = CommandType.StoredProcedure
    8.  
    9.         Dim r As SqlDataReader
    10.         Dim Table As DataTable = dataset.Tables(0)
    11.  
    12.         Try
    13.             con.Open()
    14.             r = cmd.ExecuteReader
    15.             Do While r.Read
    16.  
    17.                 Dim row As DataRow = Table.NewRow
    18.  
    19.                 row("ID") = CType(r("ID"), Integer)
    20.                 row("Time") = CType(r("Time"), DateTime)
    21.                 row("Tracker") = CType(r("Tracker"), String)
    22.                 row("TrackerType") = CType(r("TrackerType"), Integer)
    23.                 row("Hash") = CType(r("Hash"), Byte())
    24.                 row("Section") = CType(r("Section"), String)
    25.                 row("Name") = CType(r("Name"), String)
    26.                 row("Description") = CType(r("Description"), String)
    27.                 row("Size") = CType(r("Size"), Integer)
    28.                 row("Seeds") = CType(r("Seeds"), Integer)
    29.                 row("Peers") = CType(r("Peers"), Integer)
    30.                 row("InfoUrl") = CType(r("InfoUrl"), String)
    31.  
    32.                 Table.Rows.Add(row)
    33.  
    34.             Loop
    35.         Finally
    36.             con.Close()
    37.         End Try
    38.  
    39.     End Sub
    Last edited by Kt3; May 14th, 2004 at 08:09 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width