Object reference not set to an instance of an object

Hi there, I hope your help.

I try this query in asp net, but receive this alert, can you help me?
thanks in advance.

Server Error in ‘/’ Application.

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 618:
Line 619: DataSet myDataSet = new DataSet();
Line 620: foreach (DataRow row in myDataSet.Tables[strQuery].Rows)
Line 621: {
Line 622: string seriesName = row[“t_previous_year”].ToString();

Source File: d:\Inetpub\wwwroot\public\Chart.aspx Line: 620

   private void Page_Load(object sender, System.EventArgs e)

       OdbcConnection myConnectionString = new OdbcConnection(ConfigurationManager.ConnectionStrings["ConnMySQL"].ConnectionString);

String strQuery = " SELECT " +
                  " t_previous_year AS tpy " +
                  ",t_current_year AS tcy " +
                  " FROM myTbl2 " +
                  " ORDER BY ID DESC; ";

       OdbcCommand objCmd = new OdbcCommand(strQuery, myConnectionString);
       objCmd.CommandType = CommandType.Text;
       objCmd.CommandText = strQuery;

       DataSet myDataSet = new DataSet();
       foreach (DataRow row in myDataSet.Tables[strQuery].Rows)
       string seriesName = row["t_previous_year"].ToString();
       Chart1.Series[seriesName].ChartType = SeriesChartType.Line;
       Chart1.Series[seriesName].BorderWidth = 2;



You are using the SQL query string as the table identifier?

thanks for your reply.
I have changed method but I have this alert.
Attach the code file aspx.

Server Error in ‘/’ Application.

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0029: Cannot implicitly convert type ‘System.Data.Odbc.OdbcConnection’ to ‘System.Data.SqlClient.SqlConnection’

Source Error:

Line 42: conn.Open();
Line 43: cmd.CommandText = sSQL;
Line 44: cmd.Connection = conn;
Line 45: SqlDataReader dr;
Line 46: dr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

You are declaring a datareader of the wrong type, given you are using ODBC you’ll need to use the described type. Or use the more generic IDataReader which works with all datareader implementations.

Ok, I understand your observation, thanks a lot.