question

BrandonStewart-4522 avatar image
0 Votes"
BrandonStewart-4522 asked DuaneArnold-0443 commented

Visual Basic database support under .NET Core 5

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.

dotnet-adonet
· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Whatever database you are trying to use, I don't see why you cannot just use straight-up ADO.NET, database command objects and T-SQL manually to access a given database provider's database.

I think it comes down to do you know how to use ADO.NET manually without Mr. Wizard?

1 Vote 1 ·

No, I don't know how to use it without "Mr. Wizard". But that's not the point. The wizard should work - or it should be remove it all together.
Microsoft needs to either stop breaking crap, or stop expecting people to want to use their broken products.

My database apps are very, very simple. Or, at least they should be, which is the reason for using Visual Basic and it's wizards to begin with. If I lose that simplicity, then I need to drop Microsoft products and go with a different design environment which is just a quick and easy for my simple needs.

0 Votes 0 ·

No, I don't know how to use it without "Mr. Wizard". But that's not the point. The wizard should work - or it should be remove it all together.
Microsoft needs to either stop breaking crap, or stop expecting people to want to use their broken products.

And you expect to jump from the .NET Framework to .NET Core, like it's a stroll in the park? No, that's not happening.

IMHO you need to stop using Mr. Wizard and learn how to do things without Mr. Wizard, if you expect to be using .NET Core.

And the Mr. Wizard as you say works for .Net Framework solutions, then maybe its best to stay on the .Net Framework version 4.8 where .NET Framework will stop forever.

And if what you need to do is move to another platform and programming language, then you should do it.

But I suggest that you go to the VB.NET forum in QandA and talk to the VB community experts there about .NET Core 5.0,Visual Stuido 2019 and Mr. Wizard being viable.

0 Votes 0 ·

.I have used entity framework in .net 5 with c# and it has at least some wizards to aid with generating the database context and other classes.from a ready made SQL server model. Why should VB.NET programmers expect less?

0 Votes 0 ·

In fairness to Microsoft, because they are trying to push everyone toward subscription and cloud services (which is the computer version of extortion) Visual Basic being a desktop powerhouse kind of hinders that objective because as long as dektop apps are easy to build and maintain, businesses and individual developers have no realistic incentive to switch over to cloud (extortion) services. That's Microsoft's new business model and their right, I suppose. If I could delete this thread/question I would because I see no point in beating a dead horse. Other than finishing up a few apps, I've made the decision to completely dump Microsoft development products and make a clean switch to Elements from RemObjects.. I've been tinkering with it the last month and converse regularly with its developers. I won't be monitoring this thread anymore because it has come time to part ways with the Enterprise Microsoft that is no longer the consumer's Microsoft.

0 Votes 0 ·

C# is an ISO and ECMA standard controlled by those committees. VB.NEF is not a standard. You should ask MS why VB,NET is not keeping pace.

0 Votes 0 ·

1 Answer

DanielZhang-MSFT avatar image
0 Votes"
DanielZhang-MSFT answered DuaneArnold-0443 commented

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.
78559-317.png
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")
     Try
         con.Open()
    
         If con.State = ConnectionState.Open Then
             MsgBox("Connected")
         Else
             MsgBox("Not Connected!")
    
         End If
     Catch ex As Exception
         MsgBox(ex.Message)
     Finally
         con.Close()
     End Try
     Try
         Dim sql As String
         Dim cmd As New OleDb.OleDbCommand
         Dim dt As New DataTable
         Dim da As New OleDb.OleDbDataAdapter
         con.Open()
         sql = "Select * from Table1"
         cmd.Connection = con
         cmd.CommandText = sql
         da.SelectCommand = cmd
    
         da.Fill(dt)
    
         DataGridView1.DataSource = dt
     Catch ex As Exception
         MsgBox(ex.Message)
     Finally
         con.Close()
     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.



317.png (6.6 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I have found that you can use Classes Generated by .Net Framework Wizard in the .Net Core 5 environment. What I do is create a simple console project using .Net 4.7 or 4.8 then use the database wizard to create the classes. Copy the classes over to my .Net 5 project and add it. The only thing you will need to change in your class is perhaps the Connection String definition since Global Appsettings are not naturally read. Until they put support for the wizard in for .Net 5 - Just build the class in .Net framwork and copy.

0 Votes 0 ·

If the classes are just container objects with simple gets and sets no logic, then they can be used in any version of .NET framework, becuase they are just simple data container classes/objects that are generated.

I kind of doubt that a generated DBContext class from a .NET Framework would work with .NET EF Core.

0 Votes 0 ·