0% found this document useful (0 votes)
30 views3 pages

Notasform Oledbconnection Oledbcommand Oledbdataadapter Eventargs Oledbconnection

This code defines a form class in Visual Basic for managing student grades. It includes methods for loading data into combo boxes to select a period, branch, student, and enrollment from related database tables. Methods are also defined for inserting, updating, and clearing grade data using ADO.NET objects and SQL commands to connect to a SQL Server database.

Uploaded by

CésarEdu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views3 pages

Notasform Oledbconnection Oledbcommand Oledbdataadapter Eventargs Oledbconnection

This code defines a form class in Visual Basic for managing student grades. It includes methods for loading data into combo boxes to select a period, branch, student, and enrollment from related database tables. Methods are also defined for inserting, updating, and clearing grade data using ADO.NET objects and SQL commands to connect to a SQL Server database.

Uploaded by

CésarEdu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

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

You might also like