Hello,
See my code sample on GitHub which should set you up for interacting with SQL-Server. The interface has just enough to show it works so some columns for identifiers are showing which is actually good for learning purposes.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have looked everywhere to find a way to connect a database in a .NET5 Windows Form Application. I can do it using a Windows Frameworks WIndows Forms Application but I am trying to figure out how to do this with the .NET5. Is there any way to do this or is a feature that is being worked on. I am learning C# right now and would like to be able to use .Net5 to build application. Thanks, Bernard A. Bailey, Jr.
Hello,
See my code sample on GitHub which should set you up for interacting with SQL-Server. The interface has just enough to show it works so some columns for identifiers are showing which is actually good for learning purposes.
Hi BernardBailey-0080,
When you create a new project, you need to choose Windows Forms App(.NET).
Then right click you project name in solution explore->Properties->In the Application page, change your target framework to .NET 5.0.
And I made a test via sql server, it worked fine.
Here is a code example you can refer to.
using System.Data.SqlClient;
private void button1_Click(object sender, EventArgs e)
{
SqlConnection cnn;
string connStr ="ConnectString"
cnn = new SqlConnection(connStr);
cnn.Open();
DataSet ds = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter("SELECT Name from test", cnn);
adapter.Fill(ds);
this.listBox1.DataSource = ds.Tables[0];
this.listBox1.DisplayMember = "Name";
}
Best Regards,
Daniel Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
ADO.NET is ADO.NET. It basically makes no difference what version of .NET you use, if you know the basic fundlementals of how to use ADO.NET.
https://www.c-sharpcorner.com/UploadFile/18fc30/understanding-the-basics-of-ado-net/
https://dotnettutorials.net/lesson/ado-net-using-sql-server/
Hi BernardBailey-0080,
I came across this site when searching for help with a similar issue of not being able to create an SQL connection in a vb.net .NET5 Windows Desktop Application.
My solution was to add a NuGet package called "System.Data.SqlClient" by Microsoft. You can open the NuGet Package manager by going to Tools > NuGet Package Manager... > Manage NuGet Packages for Solution...
Hopefully, this will help you or others looking for a solution.