I have a problem with my C# application and I don't know how to deal with that. It's an app for my studies and it's first time I am using a C# and Visual Studio.
So - I have main form Form1
with a MenuStrip where I can go to another forms (which are datatables from my dataset displayed in a DataGridView). I can work in connectionless mode (writing data to .xml file) and in connection mode (sync directly to my database).
In main form I have a Switch_btn
button where I can change a mode I am working in. It's using a class:
public static class Connection_mode
{
public static int connection = 0;
}
It's just changing the value of one variable like that:
Connection_mode.connection = 1;
In another form (class) Function
I have a method which updates a database:
public void MethodToExec()
{
this.ds.WriteXml("D:\\sth.xml");
this.dataSet_baza.Tables["funkcja"].Merge(funkcjaTable);
this.funkcjaTableAdapter.Update(dataSet_baza.funkcja);
}
When I am in connectionless mode I have a local DataTable on which I am making changes. And in this form it's working and send all data from local table to the database - it's nice.
And it's my main question:
I want to sync data with a database when I click a Switch_btn
in main Form1
. I can have all other forms closed but when I click Switch I want to exec the MethodToExec()
from Function
form.
I've tried sth like that in Switch_btn
code:
var funkcja = new Function();
funkcja.MethodToExec();
But it's not updating the database.
Maybe there is better way to do that but I don't know how.