none
Restaurar consulta sql dinámico RRS feed

  • Pregunta

  • Hola , necesito que una vez realice una consulta en mi base de datos mysql en forma dinámica pueda restaurar otra vez para seguir usando por como estaba por defecto,es decir con el dataset y bindisourse que se ejecuto el formulario, les muestro como en el botón Restaurar como trato de restaurar pero la consulta dinámica se mantiene ejecutado.
    Imports MySql.Data.MySqlClient
    Public Class Form1
    
        Private TableManager As MySqlDataAdapter
        Dim strConn As String = My.Settings.ConnectionStringbdopm
        Dim tablabindisource As New BindingSource
        Dim tabladataset As New DataSet
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.VentaTableAdapter.Fill(Me.DataSetbdopm.venta)
        End Sub
    
        Private Sub Consulta_Click(sender As Object, e As EventArgs) Handles Consulta.Click
            TableManager = New MySqlDataAdapter("SELECT * from venta where planilla = " & TextBox1.Text & ";", strConn)
            Dim builder As MySqlCommandBuilder = New MySqlCommandBuilder(TableManager)
            tabladataset.Clear()
            TableManager.Fill(tabladataset)
            tablabindisource.DataSource = tabladataset.Tables(0)
            VentaBindingSource.DataSource = tabladataset.Tables(0)
            VentaBindingNavigator.BindingSource = tablabindisource
        End Sub
    
        Private Sub Restaurar_Click(sender As Object, e As EventArgs) Handles Restaurar.Click
            VentaDataGridView.DataSource = VentaBindingSource
            Me.VentaTableAdapter.Fill(Me.DataSetbdopm.venta)
        End Sub
    
    End Class

    • Cambiado Enrique M. Montejo sábado, 24 de marzo de 2018 7:52 Pregunta relacionada con el acceso a datos con MySql.
    jueves, 22 de marzo de 2018 4:12

Respuestas

  • Ya encontré el error, comparto el código correcto.
    Imports MySql.Data.MySqlClient
    
    Public Class Form1
    
        Private TableManager As MySqlDataAdapter
        Dim strConn As String = My.Settings.ConnectionStringbdopm
        Dim tablabindisource As New BindingSource
        Dim tabladataset As New DataSet
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.VentaTableAdapter.Fill(Me.DataSetbdopm.venta)
        End Sub
    
        Private Sub Consulta_Click(sender As Object, e As EventArgs) Handles Consulta.Click
            TableManager = New MySqlDataAdapter("SELECT * from venta where planilla = " & TextBox1.Text & ";", strConn)
            Dim builder As MySqlCommandBuilder = New MySqlCommandBuilder(TableManager)
            tabladataset.Clear()
            TableManager.Fill(tabladataset)
            tablabindisource.DataSource = tabladataset.Tables(0)
            VentaDataGridView.DataSource = tabladataset.Tables(0)
            VentaBindingNavigator.BindingSource = tablabindisource
        End Sub
    
        Private Sub Restaurar_Click(sender As Object, e As EventArgs) Handles Restaurar.Click
            VentaDataGridView.DataSource = VentaBindingSource
            VentaBindingNavigator.BindingSource = VentaBindingSource
            Me.VentaTableAdapter.Fill(Me.DataSetbdopm.venta)
        End Sub
    
    End Class

    • Marcado como respuesta Dani Paredez sábado, 24 de marzo de 2018 20:04
    sábado, 24 de marzo de 2018 20:04