473,407 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Error?? DataTable

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)

Nov 15 '05 #1
1 1293
I figured it out. Thanks

"Kelvin Nguyen" <ha******@neo.tamu.edu> wrote in message
news:eX*************@TK2MSFTNGP10.phx.gbl...
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)


Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: Eva | last post by:
Hi i am trying to insert a new row into one of my datatabels that i have in my dataset when a button is clicked. here is my code Dim ClientInsRow As DataRow = dtClient.NewRo ...
2
by: tshad | last post by:
I am getting the error: **************************************************************************** Array does not have that many dimensions. Description: An unhandled exception occurred during...
1
by: cindy | last post by:
Get data into datatable, add to dataset dsSearch " Get data into datatable, add to dataset dsSearch Using In-Memory SQL Engine join the tables and select the filenames from the join, add to...
3
by: Jon | last post by:
I'm learning about datatables. When using the example provided by MS in the ..NET Framework Class Library for DATATABLE (see below) I get an error on line 3 that says "Type expected". Is something...
0
by: funky4you | last post by:
I am using a simple select query in C# app that fetches a row which has a datatime field. The query is simple "SELECT * FROM THE USERS WHERE USER_NAME = 'ABC' ", the users table contains a...
0
by: funky4you | last post by:
I am using a simple select query in C# app that fetches a row which has a datatime field. The query is simple "SELECT * FROM THE USERS WHERE USER_NAME = 'ABC' ", the users table contains a...
0
by: Anish G | last post by:
Hi All, I am getting the below given error while running my application in live server. In my local machine, its working fine. Please help me as it is very urgent for me. Exception from...
0
by: Danny | last post by:
Hi, we just have launched our first beta version of our new product page which was developed with ASP.NET. Now we noticed that we sometimes get the error attached below. After a little web...
1
by: Danny | last post by:
Hi guys, I sometimes get the following error on my ASP.NET webpage. Server Error in '/' Application. -------------------------------------------------------------------------------- ...
6
by: fniles | last post by:
I am using VB.NET 2005 and Access database. My program uses a timer that kicks in every 1 min to read from a database and copy the dataset table to a datatable. This database is in a class called...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.