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,967
  • 6
  • 46
  • 67
user137348
  • 10,166
  • 18
  • 69
  • 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
  • 1,026,079
  • 266
  • 2,566
  • 2,900
1

Maybe the error is referring to SqlDataSource1 being null?

Christian Hayter
  • 30,581
  • 6
  • 72
  • 99