Murray Brown
asked on
Excel VBA/VB.net Recordsets Accesss & SQL databases
Hi
I am migrating an Excel VBA project that work with a backend Access database to a VB.net Excel Add-in that interacts with Access and SQL. The original project code uses Recordsets (as shown in the code below), which the project sponsor would like me to use in VB.net. Is this even possible (given that I need to interact with SQL as well as Access). I usually use ADO.net.
Sub RefreshList()
'On Error Resume Next
With Me.Lst_Empl
.BoundColumn = 1
.ColumnCount = 7
.ColumnHeads = False
.TextColumn = True
.ColumnWidths = 5
.ListStyle = fmListStyleOption
.ColumnWidths = "100,100,60,50"
End With
Lst_Empl.Clear
Call RSConnect
If RSSupp.EOF Then
'MsgBox "No Supplier Data or Recordset Lost"
Exit Sub
End If
RSSupp.MoveFirst
Do While Not RSSupp.EOF
Lst_Empl.AddItem RSSupp.Fields("First_Name" )
If IsNull(RSSupp.Fields("Last _Name")) Then
Lst_Empl.Column(1, Lst_Empl.ListCount - 1) = ""
Else
Lst_Empl.Column(1, Lst_Empl.ListCount - 1) = RSSupp.Fields("Last_Name") .Value
End If
If IsNull(RSSupp.Fields("Empl oyee_Type" )) Then
Else
Lst_Empl.Column(2, Lst_Empl.ListCount - 1) = RSSupp.Fields("Employee_Ty pe").Value
End If
If IsNull(RSSupp.Fields("Acti ve")) Then
Else
Lst_Empl.Column(3, Lst_Empl.ListCount - 1) = RSSupp.Fields("Active").Va lue
End If
If IsNull(RSSupp.Fields("Wait er Number")) Then
Else
Lst_Empl.Column(4, Lst_Empl.ListCount - 1) = RSSupp.Fields("Waiter Number").Value
End If
If IsNull(RSSupp.Fields("Empl oyeeID")) Then
Else
Lst_Empl.Column(5, Lst_Empl.ListCount - 1) = RSSupp.Fields("EmployeeID" ).Value
End If
RSSupp.MoveNext
Loop
End Sub
I am migrating an Excel VBA project that work with a backend Access database to a VB.net Excel Add-in that interacts with Access and SQL. The original project code uses Recordsets (as shown in the code below), which the project sponsor would like me to use in VB.net. Is this even possible (given that I need to interact with SQL as well as Access). I usually use ADO.net.
Sub RefreshList()
'On Error Resume Next
With Me.Lst_Empl
.BoundColumn = 1
.ColumnCount = 7
.ColumnHeads = False
.TextColumn = True
.ColumnWidths = 5
.ListStyle = fmListStyleOption
.ColumnWidths = "100,100,60,50"
End With
Lst_Empl.Clear
Call RSConnect
If RSSupp.EOF Then
'MsgBox "No Supplier Data or Recordset Lost"
Exit Sub
End If
RSSupp.MoveFirst
Do While Not RSSupp.EOF
Lst_Empl.AddItem RSSupp.Fields("First_Name"
If IsNull(RSSupp.Fields("Last
Lst_Empl.Column(1, Lst_Empl.ListCount - 1) = ""
Else
Lst_Empl.Column(1, Lst_Empl.ListCount - 1) = RSSupp.Fields("Last_Name")
End If
If IsNull(RSSupp.Fields("Empl
Else
Lst_Empl.Column(2, Lst_Empl.ListCount - 1) = RSSupp.Fields("Employee_Ty
End If
If IsNull(RSSupp.Fields("Acti
Else
Lst_Empl.Column(3, Lst_Empl.ListCount - 1) = RSSupp.Fields("Active").Va
End If
If IsNull(RSSupp.Fields("Wait
Else
Lst_Empl.Column(4, Lst_Empl.ListCount - 1) = RSSupp.Fields("Waiter Number").Value
End If
If IsNull(RSSupp.Fields("Empl
Else
Lst_Empl.Column(5, Lst_Empl.ListCount - 1) = RSSupp.Fields("EmployeeID"
End If
RSSupp.MoveNext
Loop
End Sub
Don't use recordset in .NET, use ADo.NET
What is Lst_Empl?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks very much