Imports System.
Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Public Class NotasForm
Dim conexion As OleDb.OleDbConnection
Dim comando As OleDb.OleDbCommand
Dim adapter As New OleDb.OleDbDataAdapter
Private Sub NotasForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
conexion = New OleDb.OleDbConnection
conexion.ConnectionString = "Provider=SQLOLEDB;Data Source=CESAR94;Initial
Catalog=bdPlenitud;User ID=sa;Password=123456"
MsgBox("conectado")
Try
comando = conexion.CreateCommand
comando.CommandText = "SELECT NOMBRE_PER from PERIODO"
adapter.SelectCommand = comando
Dim Periodo As New DataTable
adapter.Fill(Periodo)
CbxPeriodo.DataSource = Periodo
CbxPeriodo.DisplayMember = "NOMBRE_PER"
CbxPeriodo.ValueMember = "NOMBRE_PER"
CbxPeriodo.Text = "Seleccione el Periodo"
Catch ex As Exception
End Try
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles btnGuardar.Click
Dim comando As New OleDb.OleDbCommand
Try
If Not conexion.State = ConnectionState.Open Then
conexion.Open()
MessageBox.Show("Conexin exitosa")
End If
comando.Connection = conexion
comando.CommandText = "insert into NOTAS VALUES ('" &
Me.CbxMatricula.SelectedValue & "','" & Me.TextBox4.Text & "','" & Me.TextBox5.Text &
"','" & Me.TextBox6.Text & "')"
comando.ExecuteNonQuery()
conexion.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles
btnModificar.Click
Try
If Not conexion.State = ConnectionState.Open Then
conexion.Open()
MessageBox.Show("Conexin exitosa")
End If
comando.Connection = conexion
comando.CommandText = "Update NOTAS set CODIGO_MAT = '" &
Me.CbxMatricula.SelectedValue & "',NOTA1_NOT ='" & Me.TextBox4.Text &
"',NOTA2_NOT='" & Me.TextBox5.Text & "',NOTA3_NOT='" & Me.TextBox6.Text & "' where
CODIGO_MAT = '" & Me.CbxMatricula.SelectedValue & "'"
comando.ExecuteNonQuery()
conexion.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles btnLimpiar.Click
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox6.Clear()
TextBox2.Focus()
End Sub
Private Sub CbxPeriodo_SelectedIndexChanged(sender As Object, e As EventArgs)
Handles CbxPeriodo.SelectedIndexChanged
Try
comando.CommandText = "SELECT NOMBRE_RAM from
RAMA,HORARIO,MATRICULA,PERIODO where PERIODO.CODIGO_PER =
MATRICULA.CODIGO_PER and MATRICULA.CODIGO_HOR = HORARIO.CODIGO_HOR and
HORARIO.CODIGO_RAM = RAMA.CODIGO_RAM and NOMBRE_PER='" &
CbxPeriodo.SelectedValue & "'"
adapter.SelectCommand = comando
Dim Rama As New DataTable
adapter.Fill(Rama)
CbxRama.DataSource = Rama
CbxRama.DisplayMember = "NOMBRE_RAM"
CbxRama.ValueMember = "NOMBRE_RAM"
CbxRama.Text = "Seleccione rama"
Catch ex As Exception
End Try
End Sub
Private Sub CbxRama_SelectedIndexChanged(sender As Object, e As EventArgs)
Handles CbxRama.SelectedIndexChanged
Try
comando.CommandText = "SELECT NOMBRE_ALU,APELLIDO_ALU,
NOMBRE_ALU+' '+ APELLIDO_ALU as NOMBRECOMPLETO from
ALUMNO,MATRICULA,HORARIO,RAMA where ALUMNO.CODIGO_ALU =
MATRICULA.CODIGO_ALU and MATRICULA.CODIGO_HOR = HORARIO.CODIGO_HOR and
HORARIO.CODIGO_RAM = RAMA.CODIGO_RAM and NOMBRE_RAM='" &
CbxRama.SelectedValue & "'"
adapter.SelectCommand = comando
Dim Alumno As New DataTable
adapter.Fill(Alumno)
CbxAlumno.DataSource = Alumno
CbxAlumno.DisplayMember = "NOMBRECOMPLETO"
CbxAlumno.ValueMember = "NOMBRECOMPLETO"
CbxAlumno.Text = "Seleccione alumno"
Catch ex As Exception
End Try
End Sub
Private Sub CbxAlumno_SelectedIndexChanged(sender As Object, e As EventArgs)
Handles CbxAlumno.SelectedIndexChanged
Try
comando.CommandText = "Select CODIGO_MAT from MATRICULA, ALUMNO
where ALUMNO.CODIGO_ALU = MATRICULA.CODIGO_ALU and NOMBRE_ALU+' '+
APELLIDO_ALU='" & CbxAlumno.SelectedValue & "'"
adapter.SelectCommand = comando
Dim Matricula As New DataTable
adapter.Fill(Matricula)
CbxMatricula.DataSource = Matricula
CbxMatricula.DisplayMember = "CODIGO_MAT"
CbxMatricula.ValueMember = "CODIGO_MAT"
CbxMatricula.Text = " "
Catch ex As Exception
End Try
Me.TextBox2.Text = Me.CbxAlumno.DataSource.rows(Me.CbxAlumno.SelectedIndex)
("NOMBRE_ALU")
Me.TextBox3.Text = Me.CbxAlumno.DataSource.rows(Me.CbxAlumno.SelectedIndex)
("APELLIDO_ALU")
End Sub
End Class