HighTechTalks DotNet Forums  

DatTable Error??? any help

Dotnet FAQs microsoft.public.dotnet.faqs


Discuss DatTable Error??? any help in the Dotnet FAQs forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Kelvin Nguyen
 
Posts: n/a

Default DatTable Error??? any help - 01-10-2004 , 07:05 PM






Would anybody please help me out?



I think my code is correct but it gave me an error I don't know what it is
please correct me.





using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

using System.Data.OleDb;

namespace Energy

{

/// <summary>

/// Summary description for tblProjectDetails.

/// </summary>

public class tblProjectDetails : System.Web.UI.Page

{

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

{

DataFromSourceToMemory("myQuestion");

}

private void DataFromSourceToMemory(string strDataSessionName)

{

// Gets rows from the data source

DataSet oDS = PhysicalDataRead();


// Stores it in the session cache

Session[strDataSessionName] = oDS;

getQuestions(oDS,strDataSessionName);


}

private DataSet PhysicalDataRead()

{

// Creates connection and command string

string mystrConn, mystrCmd;

mystrConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
Server.MapPath("dcpols.mdb");

mystrCmd = "SELECT * FROM tblQuestionLU WHERE Q_PT_PKF= 9";

OleDbDataAdapter oCMD = new OleDbDataAdapter(mystrCmd, mystrConn);

DataSet oDS = new DataSet();

oCMD.Fill(oDS, "MyProjectQuestions");

return oDS;

}

private void getQuestions(DataSet ds,string str)

{

//ArrayList myQuestionList = new ArrayList();

DataTable myQuestionTable = ds.Tables[str];


foreach(DataRow myRow in myQuestionTable.Rows)

{

foreach(DataColumn myCol in myQuestionTable.Columns)

{

Response.Write(myRow[myCol].ToString());

Response.Write("<br>");


}

}

************************************************** ************

And this is the error................





Server Error in '/Energy' 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 52: DataTable myQuestionTable = ds.Tables[str];
Line 53:
Line 54: foreach(DataRow myRow in myQuestionTable.Rows)
Line 55: {
Line 56: foreach(DataColumn myCol in myQuestionTable.Columns)




Reply With Quote
  #2  
Old   
Kelvin Nguyen
 
Posts: n/a

Default Re: DatTable Error??? any help - 01-10-2004 , 07:42 PM






Oh I figured out. Thank you though

"Kelvin Nguyen" <haiaggie (AT) neo (DOT) tamu.edu> wrote

Quote:
Would anybody please help me out?



I think my code is correct but it gave me an error I don't know what it is
please correct me.





using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

using System.Data.OleDb;

namespace Energy

{

/// <summary

/// Summary description for tblProjectDetails.

/// </summary

public class tblProjectDetails : System.Web.UI.Page

{

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

{

DataFromSourceToMemory("myQuestion");

}

private void DataFromSourceToMemory(string strDataSessionName)

{

// Gets rows from the data source

DataSet oDS = PhysicalDataRead();


// Stores it in the session cache

Session[strDataSessionName] = oDS;

getQuestions(oDS,strDataSessionName);


}

private DataSet PhysicalDataRead()

{

// Creates connection and command string

string mystrConn, mystrCmd;

mystrConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
Server.MapPath("dcpols.mdb");

mystrCmd = "SELECT * FROM tblQuestionLU WHERE Q_PT_PKF= 9";

OleDbDataAdapter oCMD = new OleDbDataAdapter(mystrCmd, mystrConn);

DataSet oDS = new DataSet();

oCMD.Fill(oDS, "MyProjectQuestions");

return oDS;

}

private void getQuestions(DataSet ds,string str)

{

//ArrayList myQuestionList = new ArrayList();

DataTable myQuestionTable = ds.Tables[str];


foreach(DataRow myRow in myQuestionTable.Rows)

{

foreach(DataColumn myCol in myQuestionTable.Columns)

{

Response.Write(myRow[myCol].ToString());

Response.Write("<br>");


}

}

************************************************** ************

And this is the error................





Server Error in '/Energy' 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 52: DataTable myQuestionTable = ds.Tables[str];
Line 53:
Line 54: foreach(DataRow myRow in myQuestionTable.Rows)
Line 55: {
Line 56: foreach(DataColumn myCol in myQuestionTable.Columns)






Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.