Click here to Skip to main content
15,888,733 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
Am new to VB.net and creating a project in vb.net using visual studio 2017. Am developing a church management system which uses sql server 2017 as the back end. The startup form is the login. I also have a form for setting the sql server. So i want the sql server form to run for one time until sqlserver.dat is created. Am using the sqlserver.dat as my connectionstring. So i want help on running sql server setting form for only one time so that when the sqlserver.dat is created it won't run again but will run the login form anytime i build my project

What I have tried:

As i said in the question am new in vb.net and have no idea how to go about it and thats why am asking
Posted
Updated 29-Oct-18 23:55pm

There are a lot of solutions, how to persist the boolean flag "Don't show again" ...
I prefer to write it to HKEY_CURRENT_USER Registry.
The scenario is, you ask Registry whether the settings form has been already shown like this:

C#
//opening the subkey  
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\OurSettings");
bool bShowForm = true;  
              
//if it does exist, retrieve the stored values  
if (key != null)  
{  
    if (key.GetValue("ShowSettingsForm") == "0")
      bShowForm  = false;

    key.Close();  
}  

// now show form and set key to "0"
if (bShowForm  ) 
{
  // ....
  key.SetValue("ShowSettingsForm", "0");  
}
 
Share this answer
 
v2
You need to look at persistent values - which sounds complicated, but is just another way to say "keeping a value unchanged between runs of the application", in the same way that a bookmark tells you how far through a book you had read every time you pick it up.

That's not difficult to do, but it's not as simple as just "creating a variable" because those are designed to be non-persistent - they are the same every time the app is loaded. Start here: Using Application Settings and User Settings | Microsoft Docs[^] and it explains what youj need to do. You can create a Boolean value which says "DB has been set up" and default it to false so it runs once, by reading it each time your app starts, and if it is false, you set up your DB. You then set it to true and you will ignore it all subsequent times.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900