none
Error da.Fill(dt) RRS feed

  • Pregunta

  • Hola, soy nuevo en este foro y tambien en el lenguaje VisualBasic.NET.

    Necesito ayuda porque estoy haciendo un proyecto para la institucion donde estudio y con él puedo pasar de año.

    En fin, yo trabajo con una base de datos de informix la cual esta en el instituo, el problema es que al realizar la consulta a la base de datos para que me cargue el DataGridView me da un error en el da.Fill(dt).

    Aqui les dejo el codigo:

    Imports System.Data.Odbc
    Public Class Consulta_Admin
        Dim ConnectionString As String = "DRIVER={IBM INFORMIX ODBC DRIVER (64-bit)};UID=dmenendez2015;PWD=mg31cg10;DLOC=en_US.819;CLOC=en_US.CP1252;PRO=olsoctcp;SERV=1526;SRVR=ol_informix1;HOST=10.0.29.6;DATABASE=tresie_installtech"
        Private Sub VolverToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VolverToolStripMenuItem.Click
            Admin.Show()
            Me.Visible = False
        End Sub
        Private Sub Consulta_Admin_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
            Admin.Show()
            Me.Visible = False
        End Sub
        Private Sub Consulta_Admin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        End Sub
        Private Sub btnConsultarFormulario_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConsultarFormulario.Click
            'Cargar datagrid formulario
            Dim sql As String = "select d.nombredia as Dia, h.numhorario as Hora, h.horainicio as Inicio, h.horafin as Fin, g.anocurso, g.letragrupo, asig.nombreasignatura as Asignatura, p.nombre, p.apellido, a.nombreaula as Aula from celda c, aula a, persona p, asignatura asig, grupo g, horario h, dia d where(d.iddia = c.iddia And h.idhorario = c.idhorario And g.idgrupo = c.idgrupo And asig.idasignatura = c.idasignatura And p.ci = c.ci and a.idaula=c.idaula"
            Dim conn As New OdbcConnection
            conn.ConnectionString = ConnectionString
            Dim da As OdbcDataAdapter = New OdbcDataAdapter(sql, conn)
            Dim dt As New DataTable("celda, dia, horario, grupo, asignatura, persona, aula")
            da.Fill(dt)
            Me.dtgFormulario.DataSource = dt
        End Sub
        Private Sub btnConsultarPersona_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConsultarPersona.Click
            'Cargar datagrid persona
            Dim sql As String = "select * from persona"
            Dim conn As New OdbcConnection
            conn.ConnectionString = ConnectionString
            Dim da As OdbcDataAdapter = New OdbcDataAdapter(sql, conn)
            Dim dt As New DataTable("persona")
            da.Fill(dt)
            Me.dtgPersonaConsulta.DataSource = dt
        End Sub
        Private Sub btnConsultarGrupo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConsultarGrupo.Click
            'Cargar datagrid grupo
            Dim sql As String = "select * from grupo"
            Dim conn As New OdbcConnection
            conn.ConnectionString = ConnectionString
            Dim da As OdbcDataAdapter = New OdbcDataAdapter(sql, conn)
            Dim dt As New DataTable("grupo")
            da.Fill(dt)
            Me.dtgGrupoConsulta.DataSource = dt
        End Sub

        Private Sub btnConsultarAsignatura_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConsultarAsignatura.Click
            'Cargar datagrid asugnatura
            Dim sql As String = "select * from asignatura"
            Dim conn As New OdbcConnection
            conn.ConnectionString = ConnectionString
            Dim da As OdbcDataAdapter = New OdbcDataAdapter(sql, conn)
            Dim dt As New DataTable("asignatura")
            da.Fill(dt)
            Me.dtgAsignaturaConsulta.DataSource = dt
        End Sub

        Private Sub btnConsultarAula_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConsultarAula.Click
            'Cargar datagrid aula
            Dim sql As String = "select * from aula"
            Dim conn As New OdbcConnection
            conn.ConnectionString = ConnectionString
            Dim da As OdbcDataAdapter = New OdbcDataAdapter(sql, conn)
            Dim dt As New DataTable("aula")
            da.Fill(dt)
            Me.dtgAulasConsulta.DataSource = dt
        End Sub

        Private Sub btnConsultarCurso_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConsultarCurso.Click
            'Cargar datagrid curso
            Dim sql As String = "select * from curso"
            Dim conn As New OdbcConnection
            conn.ConnectionString = ConnectionString
            Dim da As OdbcDataAdapter = New OdbcDataAdapter(sql, conn)
            Dim dt As New DataTable("curso")
            da.Fill(dt)
            Me.dtgCursosConsulta.DataSource = dt
        End Sub

        Private Sub btnConsultarHorarios_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConsultarHorarios.Click
            'Cargar datagrid horario
            Dim sql As String = "select * from horario"
            Dim conn As New OdbcConnection
            conn.ConnectionString = ConnectionString
            Dim da As OdbcDataAdapter = New OdbcDataAdapter(sql, conn)
            Dim dt As New DataTable("horario")
            da.Fill(dt)
            Me.dtgHorarioConsulta.DataSource = dt
            'Cargar datagrid dia
            Dim sql2 As String = "select * from dia"
            Dim conn2 As New OdbcConnection
            conn2.ConnectionString = ConnectionString
            Dim da2 As OdbcDataAdapter = New OdbcDataAdapter(sql2, conn2)
            Dim dt2 As New DataTable("dia")
            da2.Fill(dt2)
            Me.dtgDiaConsulta.DataSource = dt2
        End Sub

        Private Sub tbxNombrePersonaConsulta_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tbxNombrePersonaConsulta.KeyPress
            If Char.IsLetter(e.KeyChar) Then
                e.Handled = False
            ElseIf Char.IsControl(e.KeyChar) Then
                e.Handled = False
            ElseIf Char.IsSeparator(e.KeyChar) Then
                e.Handled = False
            Else : e.Handled = True
            End If
        End Sub
        Private Sub tbxApellidoPersonaConsulta_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tbxApellidoPersonaConsulta.KeyPress
            If Char.IsLetter(e.KeyChar) Then
                e.Handled = False
            ElseIf Char.IsControl(e.KeyChar) Then
                e.Handled = False
            ElseIf Char.IsSeparator(e.KeyChar) Then
                e.Handled = False
            Else : e.Handled = True
            End If
        End Sub
        Private Sub tbxCedulaPersonaConsulta_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tbxCedulaPersonaConsulta.KeyPress
            If Char.IsNumber(e.KeyChar) Then
                e.Handled = False
            ElseIf Char.IsControl(e.KeyChar) Then
                e.Handled = False
            ElseIf Char.IsSeparator(e.KeyChar) Then
                e.Handled = False
            Else : e.Handled = True
            End If
        End Sub
        Private Sub tbxIDGrupoConsulta_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tbxIDGrupoConsulta.KeyPress
            If Char.IsNumber(e.KeyChar) Then
                e.Handled = False
            ElseIf Char.IsControl(e.KeyChar) Then
                e.Handled = False
            ElseIf Char.IsSeparator(e.KeyChar) Then
                e.Handled = False
            Else : e.Handled = True
            End If
        End Sub
        Private Sub tbxNombreGrupoConsulta_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tbxNombreGrupoConsulta.KeyPress
            If Char.IsLetter(e.KeyChar) Then
                e.Handled = False
            ElseIf Char.IsControl(e.KeyChar) Then
                e.Handled = False
            ElseIf Char.IsSeparator(e.KeyChar) Then
                e.Handled = False
            Else : e.Handled = True
            End If
        End Sub
        Private Sub tbxNombreAsginaturaConsulta_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tbxNombreAsginaturaConsulta.KeyPress
            If Char.IsLetter(e.KeyChar) Then
                e.Handled = False
            ElseIf Char.IsControl(e.KeyChar) Then
                e.Handled = False
            ElseIf Char.IsSeparator(e.KeyChar) Then
                e.Handled = False
            Else : e.Handled = True
            End If
        End Sub
        Private Sub tbxNombreAulaConsulta_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tbxNombreAulaConsulta.KeyPress
            If Char.IsLetter(e.KeyChar) Then
                e.Handled = False
            ElseIf Char.IsControl(e.KeyChar) Then
                e.Handled = False
            ElseIf Char.IsSeparator(e.KeyChar) Then
                e.Handled = False
            Else : e.Handled = True
            End If
        End Sub
        Private Sub tbxNombreCursoConsulta_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tbxNombreCursoConsulta.KeyPress
            If Char.IsLetter(e.KeyChar) Then
                e.Handled = False
            ElseIf Char.IsControl(e.KeyChar) Then
                e.Handled = False
            ElseIf Char.IsSeparator(e.KeyChar) Then
                e.Handled = False
            Else : e.Handled = True
            End If
        End Sub
        Private Sub tbxNombreDiaConsulta_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tbxNombreDiaConsulta.KeyPress
            If Char.IsLetter(e.KeyChar) Then
                e.Handled = False
            ElseIf Char.IsControl(e.KeyChar) Then
                e.Handled = False
            ElseIf Char.IsSeparator(e.KeyChar) Then
                e.Handled = False
            Else : e.Handled = True
            End If
        End Sub
    End Class

    Espero encuentren una solucion pronto y agradezco desde ya al que me ayude.

    • Cambiado Enrique M. Montejo domingo, 20 de noviembre de 2016 15:44 Pregunta relacionada con el acceso a datos con Informix.
    martes, 15 de noviembre de 2016 17:05

Todas las respuestas

  • En estos casos deberías colocar el mensaje de error, pero creo que tu problema esta en la creación del DataTable, en lugar de colocar una lista de nombres de columnas allí debes colocar es un nombre para la tabla (es opcional) por ejemplo:

    Dim dt As New DataTable("MiConsulta")

    • Propuesto como respuesta Laura Ceglz martes, 15 de noviembre de 2016 18:00
    martes, 15 de noviembre de 2016 17:19