Question Make application with Host MySQL database

PsychoNINJA

Member
Joined
Sep 18, 2021
Messages
12
Programming Experience
1-3
Hello dear csharpforums.net community,

I would like to make an application on windows form for my shop and store my products in it, I can make it and store all of my product data in Microsoft Access, but I want to use a host with MySQL database and store my data in it then use my application in any laptop or PC I want and log into any account as any rank of my shopping Hierarchy and manage all products or sell or insert any of it.

sorry if this is dumb question, I just worked with .NET Core app made a console only
 
Yes, that is all doable. Do you have as specific question?
 
Sorry dear @Skydiver for my network fault, I edited my topic and wrote my questions then looks like it didn't apply after my lost connection

Q1. How to Insert all data i wanted to store them? (if only just have to replace host ip tp local host in connection string, so I can do it, if not? please let me know how to do it?)

Q2. I made a simple Main page form, then made a login register form near it, when I start the project my start up form is main form, i would like to start with login page. How to change the start up form?

Q3 (Last Q). I have 2 forms and want to have access to all properties of forms and change their variable and inputs, when trying to change, it say's the property is read-Only
 
Q1. How to Insert all data i wanted to store them? (if only just have to replace host ip tp local host in connection string, so I can do it, if not? please let me know how to do it?)
You just always save to your MySQL host by using either the DNS name of the host, or of you didn't buy a domain name and setup DNS, then the IP address of the host. You could hardcode this into your code, but the best practice is to store this in a connection strings setting for your app.

The upside with this best practice is that you can easily change the connection string without recompiling your code. The downside is that you make it easier for a sophisticated user to find your connection strings and get the user name and password used to connect to your database. Unlike .NET Framework web apps, encrypting that settings file for a .NET Framework WinForms app is not straightforward. It's even harder to encrypt for any .NET Core app without a lot of extra infrastructure and code that may or may not be cross platform compatible.
 
Q2. I made a simple Main page form, then made a login register form near it, when I start the project my start up form is main form, i would like to start with login page. How to change the start up form?
In your Application.cs, pass in your login form instead of your main form to Application.Run(). If the user successfully logs in, change the Application.MainForm to your main form. Read up on how people implement splash screens for WinForms and how they play with the ApplicationContext .
 
Q3 (Last Q). I have 2 forms and want to have access to all properties of forms and change their variable and inputs, when trying to change, it say's the property is read-Only
You are falling into the same trap a lot of beginner WinForms programmers (as well as experienced Win32 programmers transitioning into WinForms): you are using UI (e.g the View) as your data store (e.g. the Model).

You'll want to wean yourself to using one of the MV* design patterns: MVP, MVC, etc. The key idea is keep your data model separate from the view. The only job of the view is to reflect the current state of the data model, or to change things in the data model. So from there you create only one instance of the data model and pass it to the views that need it. So in your case, your data model would contain the data that you need shared between that two forms.
 
I should have mentioned in in my post #3. Beware of exposing databases directly to the Internet. The best practice is to expose a web service which only exposes a limited of set of operations (and where operation validates authorization and authentication) to the Internet, and it's the web service that talks to the database. Modern web servers are hardened to tolerate attacks. Most databases are not.
 
Back
Top Bottom