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);
myConnectionString.Open();
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.Add(seriesName);
Chart1.Series[seriesName].ChartType = SeriesChartType.Line;
Chart1.Series[seriesName].BorderWidth = 2;
}
myConnectionString.Close();
myConnectionString.Dispose();
}