
Alguien puede corregir los errores que marca mi proyecto porfavor
Publicado por Eternal (1 intervención) el 09/07/2014 22:45:25
Es una base de datos, que cuenta cuantos alumnos hombres y mujeres se registran en la biblioteca por semaan año mes, este es el codigo, no quiere ingresar registros y ya cheque que todo sea correcto la ruta y el codigo.
No se si sea mi PC que no tenga alguna actualizacion, si me pueden ayudar porfavor.LA BASE DE DATOS EN ACCES LOS CAMPOS ESTAN EN EL ORDEN CORRECTO Y LOS NOMBRES TAMBIEN. LA RUTA TAMBIEN ESTA CORRECTA, ES URGENTE EL TRABAJO ES PARA EL VIERNES AYUDENME PORFAVOR.
TAMBIEN NECESITO UN LOGIN Y EXPORTARLO A WORLD
ESTA ES LA CLASE PARA ORDENADA OBJETOS
Imports System.Data.OleDb
Public Class AccesoADatos
Dim conexion As New OleDbConnection
Public Sub Conectar(ByVal ubicacion As String)
conexion.ConnectionString = "provider=Microsoft.Ace.Oledb.12.0; data source= C:\RUTA\Biblioteca.accdb"
conexion.Open()
End Sub
Public Sub Desconectar()
conexion.Close()
End Sub
Public Sub InsertarBorrarOModificar(ByVal sentencia As String)
Dim comando As New OleDbCommand
comando.CommandText = sentencia
comando.Connection = conexion
comando.ExecuteNonQuery()
End Sub
Public Function Consultar(ByVal sentencia As String) As DataTable
Dim comando As New OleDbCommand
Dim tablaResultante As New DataTable
Dim lector As OleDbDataReader
comando.CommandText = sentencia
comando.Connection = conexion
lector = comando.ExecuteReader()
tablaResultante.Load(lector)
Return tablaResultante
End Function
Sub Conectar()
Throw New NotImplementedException
End Sub
End Class
INSERTAR REGISTROS Y CONTAR ALUMNOS
Public Class Form2
Dim ADATOS As AccesoADatos
Dim muj As Integer = 0
Dim hom As Integer = 0
Private Property Sql As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim matricula As Integer
Dim nombre As String
Dim sexo As String
Dim carrera As String
Dim sentencia As String
Dim trabajo As String
matricula = Me.txtmatricula.Text
nombre = Me.txtnombre.Text
sexo = Me.txtsexo.Text
carrera = Me.txtcarrera.Text
trabajo = Me.txttrabajo.text
' SALE ERROR QUE NO SE PUEDE INGRESAR Y AUN NO SE SI ELIMINAR TAMBIEN, LA RUTA ES CORRECTA
Try
sentencia = String.Format("INSERT INTO Alumnos (Matricula, Nombre, Sexo, Carrera, Trabajo) " &
" values ('{0}', '{1}', {2}, '{3}', {4})",
matricula, nombre, sexo, carrera, trabajo)
ADATOS.InsertarBorrarOModificar(sentencia)
MessageBox.Show(" Registro agregado exitosamente")
Catch ex As Exception
MessageBox.Show("La inserción no pudo llevarse a cabo. Ocurrió un error: " & ex.Message)
End Try
REM aqui vas a poner un codigp que los datos se inserten a la base de datos
If txtsexo.Text = "mujer" Then
muj = muj + 1
Else
If txtsexo.Text = "hombre" Then
hom = hom + 1
Else
MessageBox.Show("Datos incompletos", "Error", MessageBoxButtons.OK)
End If
End If
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ADATOS.Conectar()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
REM boton limpiar
txtnombre.Clear()
txtmatricula.Clear()
txtsexo.Clear()
txtmatricula.Focus()
End Sub
Private Function sentencia() As String
Throw New NotImplementedException
End Function
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
MessageBox.Show("Son" & muj & " Mujeres y " & hom & " Hombres ")
End Sub
End Class
LISTAR Y BORRAR
Public Class Form1
Dim d As New AccesoADatos
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
REM LISTADO COMPLETO
DataGridView1.DataSource = d.Consultar("Select * from Alumnos order by Matricula")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If IsNothing(DataGridView1.CurrentCell) Then
MessageBox.Show(" Debe seleccionar un registro para borrar")
Else
Dim renglon As Integer
renglon = DataGridView1.CurrentCell.RowIndex
Dim matricula As String
matricula = DataGridView1(0, renglon).Value.ToString()
d.InsertarBorrarOModificar("Delete From Alumnos Where matricula = " & matricula)
MessageBox.Show("El registro se eliminó satisfactoriamente")
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'AQUI QUERIA HACER QUE LOS HOMBRES Y LAS MUJERES SALIERAN EN EL TEXTBOX PARA CONTARLOS, Y AUN NO SE
' COMO EXPORTARLO A WORD
txtalumnos=
End Sub
End Class
No se si sea mi PC que no tenga alguna actualizacion, si me pueden ayudar porfavor.LA BASE DE DATOS EN ACCES LOS CAMPOS ESTAN EN EL ORDEN CORRECTO Y LOS NOMBRES TAMBIEN. LA RUTA TAMBIEN ESTA CORRECTA, ES URGENTE EL TRABAJO ES PARA EL VIERNES AYUDENME PORFAVOR.
TAMBIEN NECESITO UN LOGIN Y EXPORTARLO A WORLD
ESTA ES LA CLASE PARA ORDENADA OBJETOS
Imports System.Data.OleDb
Public Class AccesoADatos
Dim conexion As New OleDbConnection
Public Sub Conectar(ByVal ubicacion As String)
conexion.ConnectionString = "provider=Microsoft.Ace.Oledb.12.0; data source= C:\RUTA\Biblioteca.accdb"
conexion.Open()
End Sub
Public Sub Desconectar()
conexion.Close()
End Sub
Public Sub InsertarBorrarOModificar(ByVal sentencia As String)
Dim comando As New OleDbCommand
comando.CommandText = sentencia
comando.Connection = conexion
comando.ExecuteNonQuery()
End Sub
Public Function Consultar(ByVal sentencia As String) As DataTable
Dim comando As New OleDbCommand
Dim tablaResultante As New DataTable
Dim lector As OleDbDataReader
comando.CommandText = sentencia
comando.Connection = conexion
lector = comando.ExecuteReader()
tablaResultante.Load(lector)
Return tablaResultante
End Function
Sub Conectar()
Throw New NotImplementedException
End Sub
End Class
INSERTAR REGISTROS Y CONTAR ALUMNOS
Public Class Form2
Dim ADATOS As AccesoADatos
Dim muj As Integer = 0
Dim hom As Integer = 0
Private Property Sql As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim matricula As Integer
Dim nombre As String
Dim sexo As String
Dim carrera As String
Dim sentencia As String
Dim trabajo As String
matricula = Me.txtmatricula.Text
nombre = Me.txtnombre.Text
sexo = Me.txtsexo.Text
carrera = Me.txtcarrera.Text
trabajo = Me.txttrabajo.text
' SALE ERROR QUE NO SE PUEDE INGRESAR Y AUN NO SE SI ELIMINAR TAMBIEN, LA RUTA ES CORRECTA
Try
sentencia = String.Format("INSERT INTO Alumnos (Matricula, Nombre, Sexo, Carrera, Trabajo) " &
" values ('{0}', '{1}', {2}, '{3}', {4})",
matricula, nombre, sexo, carrera, trabajo)
ADATOS.InsertarBorrarOModificar(sentencia)
MessageBox.Show(" Registro agregado exitosamente")
Catch ex As Exception
MessageBox.Show("La inserción no pudo llevarse a cabo. Ocurrió un error: " & ex.Message)
End Try
REM aqui vas a poner un codigp que los datos se inserten a la base de datos
If txtsexo.Text = "mujer" Then
muj = muj + 1
Else
If txtsexo.Text = "hombre" Then
hom = hom + 1
Else
MessageBox.Show("Datos incompletos", "Error", MessageBoxButtons.OK)
End If
End If
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ADATOS.Conectar()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
REM boton limpiar
txtnombre.Clear()
txtmatricula.Clear()
txtsexo.Clear()
txtmatricula.Focus()
End Sub
Private Function sentencia() As String
Throw New NotImplementedException
End Function
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
MessageBox.Show("Son" & muj & " Mujeres y " & hom & " Hombres ")
End Sub
End Class
LISTAR Y BORRAR
Public Class Form1
Dim d As New AccesoADatos
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
REM LISTADO COMPLETO
DataGridView1.DataSource = d.Consultar("Select * from Alumnos order by Matricula")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If IsNothing(DataGridView1.CurrentCell) Then
MessageBox.Show(" Debe seleccionar un registro para borrar")
Else
Dim renglon As Integer
renglon = DataGridView1.CurrentCell.RowIndex
Dim matricula As String
matricula = DataGridView1(0, renglon).Value.ToString()
d.InsertarBorrarOModificar("Delete From Alumnos Where matricula = " & matricula)
MessageBox.Show("El registro se eliminó satisfactoriamente")
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'AQUI QUERIA HACER QUE LOS HOMBRES Y LAS MUJERES SALIERAN EN EL TEXTBOX PARA CONTARLOS, Y AUN NO SE
' COMO EXPORTARLO A WORD
txtalumnos=
End Sub
End Class
Valora esta pregunta


0