0

I have a static field in a non static class.

public class DBtools
{
     public static string ConString ="XXXXXXXXX";
}

This field is assigned to property in the code.

SqlDataSource1.ConnectionString = DBtools.ConString;

But after i run this app I'm getting a error:

Object reference not set to an instance of an object

How come this is happening? It's a static field.

C-Pound Guru
  • 15,359
  • 6
  • 47
  • 67
user137348
  • 9,888
  • 18
  • 67
  • 89

3 Answers3

3

The SqlDataSource1 object has not been initialized.

2

You have a debugger in front of you. Put a break point on that line, and when it stops investigate all the fields/variables/etc involved. It sounds like however SqlDataSource1 is defined, it is currently null.

Marc Gravell
  • 976,458
  • 251
  • 2,474
  • 2,830
1

Maybe the error is referring to SqlDataSource1 being null?

Christian Hayter
  • 29,991
  • 6
  • 70
  • 99