I wrote a c# function to populate a ext.net store. It works fine in one application, but the same code does not work in another. I am getting a System.NullReferenceException
on line 26. This is line 26:
MyConnection.ConnectionString = ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
Here is my c# function:
protected void fillStore(Ext.Net.Store store, string query)
{
SqlDataReader MyReader;
SqlConnection MyConnection = new SqlConnection();
MyConnection.ConnectionString = ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
SqlCommand fillCommand = new SqlCommand();
fillCommand.CommandText = "select id, name from b2b_group";
fillCommand.CommandType = CommandType.Text;
fillCommand.Connection = MyConnection;
fillCommand.Connection.Open();
MyReader = fillCommand.ExecuteReader(CommandBehavior.CloseConnection);
store.DataSource = MyReader;
store.DataBind();
fillCommand.Dispose();
MyConnection.Dispose();
}
For simplification, I replaces the query string that would be passed through by a hard-coded one of "select id, name from b2b_group"
.
I can not seem to figure out why it is giving a nullReferenceException
, especially seeing as I have the same code working in another project.
I know that there is some little thing I am overseeing, could anyone spot it?
Thank you so much!