Ver Mensaje Individual
  #3 (permalink)  
Antiguo 26/07/2011, 13:54
Avatar de rikakashi
rikakashi
 
Fecha de Ingreso: julio-2011
Mensajes: 226
Antigüedad: 12 años, 9 meses
Puntos: 33
Respuesta: ¿Tengo un problema con una conexión Oledb entre VB.net 2005 y Access 2007

Código vb:
Ver original
  1. Imports System.Data.OleDb
  2. Public Class Form1
  3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  4.         Dim connetionString As String
  5.         Dim cnn As OleDbConnection
  6.         connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=yourdatabasename.mdb;"
  7.         cnn = New OleDbConnection(connetionString)
  8.         Try
  9.             cnn.Open()
  10.             MsgBox("Connection Open ! ")
  11.             cnn.Close()
  12.         Catch ex As Exception
  13.             MsgBox("Can not open connection ! ")
  14.         End Try
  15.     End Sub
  16. End Class

o con este

Código vb:
Ver original
  1. Imports System.Data.OleDb
  2. Public Class Form1
  3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  4.         Dim connetionString As String
  5.         Dim connection As OleDbConnection
  6.         Dim oledbAdapter As New OleDbDataAdapter
  7.         Dim ds As New DataSet
  8.         Dim i As Integer
  9.         connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Your mdb filename;"
  10.         connection = New OleDbConnection(connetionString)
  11.         Try
  12.             connection.Open()
  13.             oledbAdapter.SelectCommand = New OleDbCommand("Your SQL Statement Here", connection)
  14.             oledbAdapter.Fill(ds)
  15.             oledbAdapter.Dispose()
  16.             connection.Close()
  17.             For i = 0 To ds.Tables(0).Rows.Count - 1
  18.                 MsgBox(ds.Tables(0).Rows(i).Item(0))
  19.             Next
  20.         Catch ex As Exception
  21.             MsgBox(ex.ToString)
  22.         End Try
  23.     End Sub
  24. End Class

Prueba con este ejemplo modificandolo con tus datos!