Question

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,

Was it helpful?

Solution

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)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top