Hi,
I'm doing an app that adds info to a MySQL BD
Imports MySql.Data.MySqlClient
Public Class curso_add
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OpenFileDialog1.Filter = "Ficheiros de Imagem |*.jpg;*.bmp;*.png;*.gif"
OpenFileDialog1.FilterIndex = "2"
OpenFileDialog1.Title = "Escolha uma imagem..."
OpenFileDialog1.InitialDirectory = "C:\"
OpenFileDialog1.ShowDialog()
End Sub
Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
Dim erro As System.IO.Stream
Try
OpenFileDialog1.CheckFileExists = True
OpenFileDialog1.ShowReadOnly = False
erro = OpenFileDialog1.OpenFile()
imagem_box.Text = OpenFileDialog1.FileName.ToString
PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)
If Not (erro Is Nothing) Then
erro.Close()
End If
Catch ex As Exception
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim con As New MySqlConnection("Server=localhost;Database=escola_musica;Uid=root;Pwd=;")
Dim sql As String = "INSERT INTO cursos(nome_curso, imagem_curso, nro_max_aluno) VALUES ('" & TextBox1.Text & "', '" & imagem_box.Text & "', '" & TextBox2.Text & "')"
Dim cmd As New MySqlCommand(sql, con)
con.Open()
Dim x As Integer = cmd.ExecuteNonQuery()
If x < 1 Then
MessageBox.Show("Erro ao inserir", My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
MessageBox.Show("Registo inserido com sucesso!", My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Information)
Gestão_Prof.Show()
Me.Close()
End If
con.Close()
cmd = Nothing
End Sub
End Class
but in the image path doesn't appear the slashes
http://img249.imageshack.us/img249/1457/semttuloayi.jpg