Hola a todos:
Este es un aporte de un principiante para la comunidad,
VB.net y base de datos Access
'recordset and connection variables
Dim rstClasses As ADODB.Recordset
Dim Cnxn As ADODB.Connection
Dim strCnxn As String
Dim strSQLClasses As String
Dim strID As String
Dim strPrompt As String
Dim fld As ADODB.Field
Dim ii As String : Dim i, j As Integer
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.Button1 = New System.Windows.Forms.Button()
Me.Label1 = New System.Windows.Forms.Label()
Me.TextBox2 = New System.Windows.Forms.TextBox()
Me.Button2 = New System.Windows.Forms.Button()
Me.Label2 = New System.Windows.Forms.Label()
Me.Label3 = New System.Windows.Forms.Label()
Me.Label4 = New System.Windows.Forms.Label()
Me.SuspendLayout()
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(16, 64)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(200, 20)
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = "ver registro"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(144, 200)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(136, 24)
Me.Button1.TabIndex = 1
Me.Button1.Text = "MoveNext registro N': ?"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(16, 24)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(72, 16)
Me.Label1.TabIndex = 2
Me.Label1.Text = "Columna N' : "
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(104, 24)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(24, 20)
Me.TextBox2.TabIndex = 3
Me.TextBox2.Text = "1"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(88, 232)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(192, 24)
Me.Button2.TabIndex = 5
Me.Button2.Text = "Busca Nombre del Textbox"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(16, 96)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(200, 16)
Me.Label2.TabIndex = 6
Me.Label2.Text = "Label2"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(16, 120)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(200, 16)
Me.Label3.TabIndex = 7
Me.Label3.Text = "Label3"
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(16, 152)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(200, 16)
Me.Label4.TabIndex = 8
Me.Label4.Text = "Label4"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label4, Me.Label3, Me.Label2, Me.Button2, Me.TextBox2, Me.Label1, Me.Button1, Me.TextBox1})
Me.Name = "Form1"
Me.Text = "Base de datos basico"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Display all the Classes
rstClasses.MoveFirst()
Do While rstClasses.EOF = False
i = Val(TextBox2.Text)
fld = rstClasses.Fields.Item(i) 'Columna 0=Class ID; Columna 1=Class Name ; ...
TextBox1.Text = fld.Value : ii = InputBox("desde 2 hasta 16", , , , ) 'Sirve como STOP nada mas !
rstClasses.MoveNext()
Loop
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim lbl(10) As Label : Dim NomE As String
lbl(1) = Label1 : lbl(2) = Label2
lbl(3) = Label3 : lbl(4) = Label4
NomE = TextBox1.Text
'********* Busqueda de vinculo entre Nombre y numero de record ***********************
BusquedaNomNum(rstClasses, NomE, fld)
'************************************************* ************************************
rstClasses.MoveFirst()
rstClasses.Move(id)
For j = 1 To 4
fld = rstClasses.Fields.Item(j) 'Columna 0=Class ID; Columna 1=Class Name ; ...
lbl(j).Text = fld.Value
Next j
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Open connection
Cnxn = New ADODB.Connection()
strCnxn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\vbnetsbs\chap19\Students.mdb;" & _
"user id=admin;password=;"
Cnxn.Open(strCnxn)
' open recordset server-side for indexing
rstClasses = New ADODB.Recordset()
rstClasses.CursorLocation = ADODB.CursorLocationEnum.adUseServer
strSQLClasses = "Classes"
rstClasses.Open(strSQLClasses, strCnxn, ADODB.CursorTypeEnum.adOpenKeyset, _
ADODB.LockTypeEnum.adLockReadOnly)
End Sub
************************************************** ***************
A esto hay que completarlo con codigo en el Modulo Standard BusquedaNomNum
Saludos,
antiguo