0

I want to use the top clause query in C#

objConnection = new SqlConnection(ConfigurationManager.AppSettings["connectionstring"].ToString());
            objConnection.Open();
            objCommand = new SqlCommand("SELECT TOP (@perpage) * FROM user_master", objConnection);
            objCommand.Parameters.AddWithValue("@perpage",objusmspass.strperpage);
            objReader = objCommand.ExecuteReader();

I am getting object reference not set to the instance of the object at line

objReader = objCommand.ExecuteReader();

Thanks,

walther
  • 13,466
  • 5
  • 41
  • 67
asifa
  • 771
  • 1
  • 28
  • 63

1 Answers1

0

Check if your either custom object objusmspass & its property is null or not, Use try catch blocks to see what kind of exception it is (sqlException or other than that)

Pravin Pawar
  • 2,559
  • 3
  • 34
  • 40
  • I checked none of my values are null. My other functions are also using the same method and they are working fine. Is there some problem in my query or something. – asifa Apr 17 '12 at 13:17
  • Did u add try catch block(s) ? What type of exception is getting caught? – Pravin Pawar Apr 17 '12 at 13:19