Array of bytes to/from MySql

Discussion in 'ASP .Net' started by Gert, Sep 13, 2005.

  1. Gert

    Gert Guest

    Hi,

    I need to store a array() of byte to a mysql field. I created a field in
    mysql of type varbinary. But storing and retrieving gives problems.

    Please help.

    The
    strTemp = EnDeCrypt(txt, psw)

    Label1.Text = strTemp



    encData = System.Text.Encoding.UTF8.GetBytes(strTemp)



    Dim myconnstring As String = "host=vmge1; "

    Dim conn As New MySql.Data.MySqlClient.MySqlConnection

    Dim cmd As New MySql.Data.MySqlClient.MySqlCommand

    Dim myDataReader As MySql.data.mysqlclient.MySqlDataReader

    Dim oParameter As New MySql.Data.MySqlClient.MySqlParameter

    conn.ConnectionString = myconnstring

    Dim strQuery As String = "UPDATE klanten SET secret=?ArrayParameter"

    Try

    conn.Open()

    cmd.Connection = conn

    cmd.CommandType = CommandType.Text

    cmd.CommandText = strQuery

    oParameter.ParameterName = "?ArrayParameter"

    oParameter.DbType = DbType.Binary

    oParameter.Value = strTemp

    Label1.Text = strTemp

    cmd.Parameters.Add(oParameter)

    cmd.ExecuteNonQuery()

    Catch ex As MySql.Data.MySqlClient.MySqlException

    Label1.Text = "Error " & ex.Number & " " & ex.Message

    End Try

    Dim strQuery2 As String = "SELECT secret from klanten"

    cmd.CommandText = strQuery2

    myDataReader = cmd.ExecuteReader()

    If myDataReader.Read Then

    Dim T As String = myDataReader.GetString(0)

    Label2.Text = T

    End If

    If Label1.Text = Label2.Text Then Label3.Text = "GELIJK" Else Label3.Text =
    "ONGELIJK"
     
    Gert, Sep 13, 2005
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.