Невозможно привести объект типа «System.Byte []» к типу «System.IConvertible». 3 - PullRequest
0 голосов
/ 10 марта 2019

Импортирует System.IO Импортирует MySql.Data.MySqlClient

Открытый класс Form1 Dim opfile как новый OpenFileDialog Dim full_file_name как строка Dim имя файла как строка Private Sub Form1_Load (отправитель как объект, e как EventArgs) обрабатывает MyBase.Загрузка

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    opfile.FileName = Nothing
    TextBox1.Text = ""

End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    'Try
    full_file_name = TextBox1.Text
        full_file_name.Split("\")
        filename = full_file_name.Last.ToString

        Dim con As MySqlConnection = New MySqlConnection("server=localhost;User Id=root;password=root;database=sampledb")
        Dim cmd As MySqlCommand = New MySqlCommand

        cmd.Connection = con
        cmd.CommandText = "insert into table1 (filename,[content]) values (@filename,@file)"

        With cmd.Parameters
            .AddWithValue("filename", filename)
            .AddWithValue("file", MySqlDbType.VarBinary).Value = File.ReadAllBytes(TextBox1.Text)
        End With
        con.Open()
        cmd.ExecuteNonQuery()
        con.Close()
        MsgBox("file saved")
        TextBox1.Clear()
        'Catch ex As Exception
    'MsgBox(ex.Message)
    'End Try
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    If opfile.ShowDialog = DialogResult.OK Then
        TextBox1.Text = opfile.FileName

    End If

End Sub

Конечный класс

...