Reference: Object reference not set to an instance of an object.
-
Not in the ConnexionMysql class, I hope? The
ConnexionMysql
object needs to exist (new ConnexionMysql) before you call any non-static methods. I suggest you create the connection when it's needed, using the standard pattern; create a IDbConnection, create an IDbCommand, open, execute.Bastard Programmer from Hell :suss:
the connexionmysql is a static class witch contain the connection with database with the method"getconnexion" and function "getdatabasenames"
-
the connexionmysql is a static class witch contain the connection with database with the method"getconnexion" and function "getdatabasenames"
-
Can you post the code of that method? That's where the error will be originating from :)
Bastard Programmer from Hell :suss:
He should be debugging it, not posting it. It's not a difficult thing for him to do.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
-
Stick a breakpoint on the line that's raising the exception. Run the application, and follow the steps necessary to get to that point. When the debugger breaks on that line, hover the mouse over ConnectionMysql and see if it's null or not. If it's not null, step into getConnexion and step through that code. This is debugging 101. How come you haven't tried this yourself?
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
combdb.SelectedItem=null
-
combdb.SelectedItem=null
And there's your problem. If this is null, don't attempt to execute the code.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
-
He should be debugging it, not posting it. It's not a difficult thing for him to do.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
-
He should be debugging it, not posting it. It's not a difficult thing for him to do.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
I stick a breakpoint on the line that's raising the exception, and i get combobox item=null
-
And there's your problem. If this is null, don't attempt to execute the code.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
i Stick a breakpoint on the line combdb.ItemsSource = ConnexionSqlServer.GetDataBasesNames() wich is the method that fill the combobox, i get the exception on combobox although the method returns the names of the database when I test every single button while it works but the problem is when I migrate from one button to another
-
When the selection in a ComboBox changes, you get TWO (2) SelectionChanged events: - the originally selected item gets unselected, and nothing is selected - the new item gets selected Therefore always check that
combdb.SelectedItem
is not nothing before you use it!i Stick a breakpoint on the line combdb.ItemsSource = ConnexionSqlServer.GetDataBasesNames() wich is the method that fill the combobox, i get the exception on combobox although the method returns the names of the database when I test every single button while it works but the problem is when I migrate from one button to another
-
i Stick a breakpoint on the line combdb.ItemsSource = ConnexionSqlServer.GetDataBasesNames() wich is the method that fill the combobox, i get the exception on combobox although the method returns the names of the database when I test every single button while it works but the problem is when I migrate from one button to another
When you update the contents of a ComboBox, you cannot always assume that the SelectedIndex will get set to a valid item; often it winds up set to -1; depending on the circumstances. You need some defensive code; e.g.
if ( cb.Count > 0 ){
if ( cb.SelectedIndex < 0 || cb.SelectedIndex >= cb.Count ) {
cb.SelectedIndex = 0;
} else {
... // Bail out.
}
}