Imports System.Data.OleDb
Imports System.IO
Public Class Form1
Private conex As New OleDbConnection
Private Sub conexion()
conex.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Basedatosproyecto.mdb"
conex.Open()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
conexion()
picFoto.SizeMode = PictureBoxSizeMode.StretchImage
End Sub
Private Sub exam_Click(ByVal sender As Object, ByVal e As EventArgs) Handles exam.Click
Dim ofd As New OpenFileDialog
ofd.Filter = "Imagenes JPG|*.jpg"
If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
picFoto.Image = Image.FromFile(ofd.FileName)
End If
End Sub
Private Sub guar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles guar.Click
Try
Dim ms As New MemoryStream
picFoto.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim pic As Byte() = ms.GetBuffer
If TextBox1.Text <> "" And pic.Length > 0 Then
Dim cmd As New OleDbCommand("insert into Alumnos values(@nom,@con,@sem,@esp,@apro,@curs,@prom,@pic)", conex)
cmd.Parameters.Add(New OleDbParameter("@nom", TextBox1.Text))
cmd.Parameters.Add(New OleDbParameter("@con", TextBox3.Text))
cmd.Parameters.Add(New OleDbParameter("@sem", TextBox2.Text))
cmd.Parameters.Add(New OleDbParameter("@esp", TextBox4.Text))
cmd.Parameters.Add(New OleDbParameter("@apro", TextBox5.Text))
cmd.Parameters.Add(New OleDbParameter("@curs", TextBox6.Text))
cmd.Parameters.Add(New OleDbParameter("@prom", TextBox7.Text))
cmd.Parameters.Add(New OleDbParameter("@pic", pic))
cmd.ExecuteNonQuery()
MsgBox("Los registros se han almacenado satisfactoriamente")
Else
MsgBox("Debe agregar todos los datos")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class