+ 3
Can I save variables in a Winforms C# database?
How can I save my variables in a database and change its value every time I want from code?
1 Respuesta
+ 1
Start thinking in data-objects and methods/functions.
A form is just a tool, to get input.
So there is a person with a name
Then there is a database with a table persons
This table has one column "Name"
This is the code to insert one row with the name Alice
you save the code in the database
using a sqlconnection and sqlcommand
first_name = "alice";
using (SqlConnection con = new SqlConnection(
ConsoleApplication1.Properties.Settings.Default.masterConnectionString))
{
con.Open();
try
{
using (SqlCommand command = new SqlCommand(
"INSERT INTO Persons VALUES(@Name)", con))
{
command.Parameters.Add(new SqlParameter("Name", first_name));
command.ExecuteNonQuery();
}
}
catch
{
Console.WriteLine("Could not insert.");
}
}
http://csharp-station.com/Tutorial/AdoDotNet/Lesson03
https://www.dotnetperls.com/sqlclient