Object reference not set to instance of an object
-
i am trying to run this code but it always gives me this error"Object reference not set to instance of an object" and here is my code try { DataAcces datc=new DataAcces(); this.txtID.DataBindings.Add("Text",datc.dsDisplay.Tables["Customers"],"CustomerID"); this.txtName.DataBindings.Add("Text",datc.dsDisplay.Tables["Customer"],"CustomerName"); this.txtSurname.DataBindings.Add("Text",datc.dsDisplay.Tables["Customers"],"CustomerSurname"); this.txtEmail.DataBindings.Add("Text",datc.dsDisplay.Tables["CustomerEmail"],"CustomerEmail"); } catch(Exception ex) { MessageBox.Show(ex.Message); }
-
i am trying to run this code but it always gives me this error"Object reference not set to instance of an object" and here is my code try { DataAcces datc=new DataAcces(); this.txtID.DataBindings.Add("Text",datc.dsDisplay.Tables["Customers"],"CustomerID"); this.txtName.DataBindings.Add("Text",datc.dsDisplay.Tables["Customer"],"CustomerName"); this.txtSurname.DataBindings.Add("Text",datc.dsDisplay.Tables["Customers"],"CustomerSurname"); this.txtEmail.DataBindings.Add("Text",datc.dsDisplay.Tables["CustomerEmail"],"CustomerEmail"); } catch(Exception ex) { MessageBox.Show(ex.Message); }
Have you stepped through in a debugger to see which line is giving you a null reference ? What's DataAcces ? The typo tells me it's not a framework class, so we can't possibly know what it does, how it works, or why you may have this error. The controls could be null. The dsDisplay property could be null. It may not contain a table called 'Customers'. Etc.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
Have you stepped through in a debugger to see which line is giving you a null reference ? What's DataAcces ? The typo tells me it's not a framework class, so we can't possibly know what it does, how it works, or why you may have this error. The controls could be null. The dsDisplay property could be null. It may not contain a table called 'Customers'. Etc.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
IF you mean DataAcces datc=new DataAcces(); then you need to step into the code, something in the constructor for your class is failing. If this is a data tier, the methods should probably be static, so you don't need to create one every time.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog