Visual Basic database support under .NET Core 5

Brandon Stewart 136 Reputation points

I have a couple of Visual Basic apps, each of which connects to a local Microsoft Access database. I have upgraded my apps from using the .NET Framework to now use .NET Core 5. For some reason, I can no longer add a new data source via the wizard, nor by manually coding. I can still do it when creating VB WinForms app under the Framework, but not under .NET 5. This should be incredibly simply to do. Does VB under .NET 5 no longer support connecting to a database? I cannot find anything on a Google search which mentions anything about connecting to a local database under .NET 5, and the methods of doing it under .NET Framework don't seem to work.

Microsoft Technologies based on the .NET software framework.
3,638 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,621 Reputation points

    Hi BrandonStewart-4522,
    Follow the steps below, you will find that "this window is not supported for the selected project." in Winforms(VB) .NET5.
    1.Open the Data Sources window, on the View menu, select Other Windows > Data Sources.
    It means that the wizard is not supported yet. So you need to connect to the database manually.
    I made a test and can access the local Microsoft Access database successfully.
    First add data connection in Server Explorer which on View menu.
    Then use the following code example to load records from Access Database to Datagridview.

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load  
        Dim con As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\danielzh\Desktop\test.accdb")  
            If con.State = ConnectionState.Open Then  
                MsgBox("Not Connected!")  
            End If  
        Catch ex As Exception  
        End Try  
            Dim sql As String  
            Dim cmd As New OleDb.OleDbCommand  
            Dim dt As New DataTable  
            Dim da As New OleDb.OleDbDataAdapter  
            sql = "Select * from Table1"  
            cmd.Connection = con  
            cmd.CommandText = sql  
            da.SelectCommand = cmd  
            DataGridView1.DataSource = dt  
        Catch ex As Exception  
        End Try  
    End Sub  

    Best Regards,
    Daniel Zhang

    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentationto enable e-mail notifications if you want to receive the related email notification for this thread.