|
-
October 28th, 2009, 09:17 AM
#1
closing code bizzare behaviour
Hi guys I'm new to C#.net so please keep that in mind.
first I'm using VS2005 i'm also using c# for developing some data base driven windows application, Im also using MySQL as my data base,
I used the DataGridView class (naturally) to display some data, but in order to add some other functionalities I encapsulated the DataGridVeiw calss with my own custom made class that saves the updates the user makes as sql queries (took care of sql injection) now what I needed is when the user closes the window (form) the queries saved are sent to MySQL so intuitively I did that in the class destructor:
Code:
~myTable()
{
if(notSynchronisedQueries.Count>0) executeNonQueries(notSynchronisedQueries);
}
protected void executeNonQueries(List<string> Queries)
{
MySqlConnection connection = new MySqlConnection(connectionString);
MySqlCommand command = new MySqlCommand();
connection.Open(); // code stops here
command.Connection = connection;
comand.Type = CommandType.Text;
for(int i=0;i<Queries.Count;i++)
{
command.CommandText += Queries[i] + "\n";
}
command.ExecuteNonQuery();
connection.Close();
}
ok string connectionString is a part of my class and List<string> notSynchronisedQueries is also a part of my class myTable.
now the problem is when the user closes the queries doesn't seem to reach the database. I tracked the code moving one statement at a time and through the use of breakpoints and noticed that the code stopped at the place indicated above it just reaches there and returns thus closing the window without updating the data base, WHY? and HOW can I solve this issue.
I also tried putting a MessageBox in the destructor it also appears but as soon as it apears it goes away and the application continues and closses the window without me even touching the message box!!!
my only guess is that the application is closing then the garbage collector is deleting the components but is stopped or just deletes before the destructor finishes but thats just my guess
please help
thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|