Results 1 to 7 of 7

Thread: Need convert this code to 2005 anyone can help?

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2006
    Posts
    11

    Arrow Need convert this code to 2005 anyone can help?

    this code work in .net 1 ,but not work in .net 2 .i conver with the 2005 but the wizard run the app but no change the code if anyone can help me?
    can correct some line but i new , for example
    i can correct Private da As OleDbDataAdapter to Private da As OleDb.OleDbDataAdapter

    this is the code:

    Option Strict On

    Imports Microsoft.VisualBasic
    Imports System
    Imports System.Windows.Forms
    Imports System.Drawing

    Imports System.Data
    Imports System.Data.OleDb

    Public Class Form1
    Inherits System.Windows.Forms.Form

    Public Sub New()
    MyBase.New()

    Application.EnableVisualStyles()
    Application.DoEvents()

    'El Diseñador de Windows Forms requiere esta llamada.
    InitializeComponent()

    'Agregar cualquier inicialización después de la llamada a InitializeComponent()

    End Sub

    ' Las variables que usaremos en este ejemplo
    Private dt As DataTable
    Private da As OleDbDataAdapter
    Private fila As Integer
    '
    Private Sub Form1_Load( _
    ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles MyBase.Load
    ' Limpiar los controles del GroupBox y
    ' deshabilitarlos hasta que se conecte a la base de datos
    '
    For Each c As Control In Me.GroupBox1.Controls
    ' Limpiar los textbox
    If TypeOf c Is TextBox Then
    c.Text = ""
    End If
    ' Deshabilitarlos
    c.Enabled = False
    Next
    Me.GroupBox1.Enabled = False
    Me.GroupBox1.Text = "Debes conectar antes de usar los datos"
    '
    ' El nombre de la base de datos:
    ' (poner el path real de la base de datos de prueba)
    Me.txtBase.Text = "E:\gsCodigo_00\VS.NET\vb y cs\acceso a datos\ejemplo_elGuille\db2000.mdb"
    End Sub

    Private Sub btnConectar_Click( _
    ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles btnConectar.Click
    ' Conectar y mostrar los datos
    ' Comprobar si existe la bse de datos
    Try
    If System.IO.File.Exists(txtBase.Text) = False Then
    MessageBox.Show("No existe la base de datos indicada")
    txtBase.Focus()
    Exit Sub
    End If
    Catch ex As Exception
    MessageBox.Show("ERROR: " & ex.Message & vbCrLf & "Seguramente porque no existe la base de datos indicada")
    txtBase.Focus()
    Exit Sub
    End Try
    '
    ' La cadena de conexión
    Dim sCnn As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & txtBase.Text
    ' La cadena de selección
    Dim sSel As String = "SELECT * FROM Prueba ORDER BY ID"
    ' Para traer solo los registros entre dos fechas
    ' sSel = "SELECT * FROM Prueba WHERE (FechaAlta >= #2006/01/05# AND FechaAlta <= #2006/01/06#)"
    '
    ' Comprobar si hay algún error
    Try
    ' Crear un nuevo objeto del tipo DataAdapter
    'Dim cnn As New OleDbConnection(sCnn)
    da = New OleDbDataAdapter(sSel, sCnn)
    ' Crear los comandos de insertar, actualizar y eliminar
    Dim cb As New OleDbCommandBuilder(da)
    ' Como hay campos con caracteres especiales,
    ' al usarlos incluirlos entre corchetes.
    cb.QuotePrefix = "["
    cb.QuoteSuffix = "]"
    ' Asignar los comandos al DataAdapter
    ' (se supone que lo hace automáticamente, pero...)
    da.UpdateCommand = cb.GetUpdateCommand
    da.InsertCommand = cb.GetInsertCommand
    da.DeleteCommand = cb.GetDeleteCommand
    '
    ' Esta base de datos usa el ID con valores automáticos
    da.MissingSchemaAction = MissingSchemaAction.AddWithKey
    '
    dt = New DataTable
    ' Llenar la tabla con los datos indicados
    da.Fill(dt)
    '
    ' Habilitar los controles
    For Each c As Control In Me.GroupBox1.Controls
    c.Enabled = True
    Next
    Me.GroupBox1.Enabled = True
    Me.GroupBox1.Text = "Conexión realizada"

    ' Y mostrar el primer registro
    If dt.Rows.Count > 0 Then
    btnFirst_Click(Nothing, Nothing)
    Else
    fila = -1
    btnActualizar.Enabled = False
    End If
    Catch ex As Exception
    MessageBox.Show("ERROR al conectar o recuperar los datos:" & vbCrLf & _
    ex.Message, "Conectar con la base", _
    MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
    End Sub

    Private Sub asignarDatos(ByVal dr As DataRow)
    ' Usar los datos que hay en los textbox
    dr("Nombre") = txtNombre.Text
    dr("e-mail") = txtEmail.Text
    dr("FechaAlta") = txtFechaAlta.Text
    dr("Comentario") = txtComentario.Text
    End Sub

    Private Sub mostrarDatos(ByVal f As Integer)
    Dim uf As Integer = dt.Rows.Count - 1
    If f < 0 OrElse uf < 0 Then Exit Sub
    '
    Dim dr As DataRow = dt.Rows(f)
    txtID.Text = dr("ID").ToString
    txtNombre.Text = dr("Nombre").ToString
    txtEmail.Text = dr("e-mail").ToString
    txtFechaAlta.Text = dr("FechaAlta").ToString
    txtComentario.Text = dr("Comentario").ToString
    '
    btnActualizar.Enabled = True
    End Sub

    Private Sub btnFirst_Click( _
    ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles btnFirst.Click
    ' Posicionarse en la primera fila
    fila = 0
    ' Mostrar los datos de la fila indicada
    mostrarDatos(fila)
    End Sub

    Private Sub btnPrev_Click( _
    ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles btnPrev.Click
    ' Posicionarse en la fila anterior
    fila = fila - 1
    If fila < 0 Then fila = 0
    ' Mostrar los datos de la fila indicada
    mostrarDatos(fila)
    End Sub

    Private Sub btnNext_Click( _
    ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles btnNext.Click
    ' Posicionarse en la fila siguiente
    Dim uf As Integer = dt.Rows.Count - 1
    fila = fila + 1
    If fila > uf Then fila = uf
    ' Mostrar los datos de la fila indicada
    mostrarDatos(fila)
    End Sub

    Private Sub btnLast_Click( _
    ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles btnLast.Click
    ' Posicionarse en la última fila
    fila = dt.Rows.Count - 1
    ' Mostrar los datos de la fila indicada
    mostrarDatos(fila)
    End Sub

    Private Sub btnActualizar_Click( _
    ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles btnActualizar.Click
    ' Actualizar los datos en la fila actual
    If fila < 0 OrElse fila > dt.Rows.Count - 1 Then Exit Sub

    Dim dr As DataRow = dt.Rows(fila)
    ' Asignar los datos de los textbox a la fila
    asignarDatos(dr)
    'dr("Nombre") = txtNombre.Text
    'dr("e-mail") = txtEmail.Text
    'dr("FechaAlta") = txtFechaAlta.Text
    'dr("Comentario") = txtComentario.Text
    ' Guardar físicamente los datos en la base
    Try
    da.Update(dt)
    dt.AcceptChanges()
    Catch ex As DBConcurrencyException
    MessageBox.Show("Error de concurrencia:" & vbCrLf & ex.Message)
    Catch ex As Exception
    MessageBox.Show(ex.Message)
    End Try
    End Sub

    Private Sub btnNuevo_Click( _
    ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles btnNuevo.Click
    ' Crear un nuevo registro
    Dim dr As DataRow = dt.NewRow()
    ' Asignar los datos de los textbox a la fila
    asignarDatos(dr)
    'dr("Nombre") = txtNombre.Text
    'dr("e-mail") = txtEmail.Text
    'dr("FechaAlta") = txtFechaAlta.Text
    'dr("Comentario") = txtComentario.Text
    ' Añadir la nueva fila a la tabla
    dt.Rows.Add(dr)
    ' Guardar físicamente los datos en la base
    Try
    da.Update(dt)
    dt.AcceptChanges()
    ' Si es el primer registro de la base,
    ' volver a leer los datos para actualizar los IDs
    If CInt("0" & dr("ID").ToString) = 0 Then
    dt = New DataTable
    da.Fill(dt)
    End If
    ' Posicionarlo en la última fila
    btnLast_Click(Nothing, Nothing)
    Catch ex As DBConcurrencyException
    MessageBox.Show("Error de concurrencia:" & vbCrLf & ex.Message)
    Catch ex As Exception
    MessageBox.Show(ex.Message)
    End Try
    End Sub

    Private Sub btnExaminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExaminar.Click
    ' Seleccionar una base de datos
    ' (aunque debe tener la tabla y campos usados en este ejemplo)
    Dim ofd As New OpenFileDialog
    ofd.Title = "Seleccionar base de datos"
    ofd.FileName = txtBase.Text
    If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
    txtBase.Text = ofd.FileName
    End If
    End Sub

    End Class

    and i have the asembly if any need!

  2. #2
    Hyperactive Member ZaNi's Avatar
    Join Date
    Jun 2006
    Location
    Australia
    Posts
    360

    Re: Need convert this code to 2005 anyone can help?

    There is too much code there. I doubt you will find anyone who will take the time required to copy/paste and debug that whole thing. I suggest you post specific lines and error messages if you want to make progress.
    * Don't limit yourself to sanity
    * I'd rather be optimistic and naive than pessimistic and right
    * Ask good questions, get good answers.

    My Codebank submissions:
    How to write one rountine to handle many events
    Accessing and Using variables across multiple forms
    Printing/Previewing a form or control

    Links I've "borrowed" from other people:
    vbdotnetboy - Awesome site for tips

  3. #3
    Hyperactive Member francisstokes's Avatar
    Join Date
    May 2005
    Location
    Kent, England
    Posts
    272

    Re: Need convert this code to 2005 anyone can help?

    Yeah. You stated you want 'help', so do what you can, and post what you can't.

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2006
    Posts
    11

    Re: Need convert this code to 2005 anyone can help?

    oka thanks for you repond guys.
    the first
    in 2005 if i write
    Imports Microsoft.VisualBasic
    Imports System
    Imports System.Windows.Forms
    Imports System.Drawing

    Imports System.Data
    Imports System.Data.OleDb

    if i write this in 2005 get imports is no a declered variable
    i no need import in 2005 or is changed?

  5. #5
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Need convert this code to 2005 anyone can help?

    Imports go at the very top of your form before anything else... can't go anywhere other than that, however, you can modify and choose the things you wish to import in 2005 in the project properties. There is a reference section where you can choose the items you wish to import, as well as adding any references that you want...
    Last edited by gigemboy; Aug 21st, 2006 at 09:59 AM.

  6. #6

    Thread Starter
    New Member
    Join Date
    Aug 2006
    Posts
    11

    Re: Need convert this code to 2005 anyone can help?

    oka at this time i have problem only with this command:
    bntfirst_click (nothing,nothing)
    i change it for:
    bntfirst.performance.click()
    is this correct?
    thanks

  7. #7
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Need convert this code to 2005 anyone can help?

    btnfirst.performclick()

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width