473,388 Members | 1,277 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,388 software developers and data experts.

DataAdapters, DataSets, DataTables

I'm confused about the relationships between these objects. I've written
this:

DataSet dsTaskActivities = new DataSet("TA");
DataTable dtTask = dsTaskActivities.Tables.Add("Tasks");
DataTable dtActivity = dsTaskActivities.Tables.Add("Activity");
OdbcCommand cmd = new OdbcCommand();
cmd.Connection = odbcIB;
cmd.CommandText = "SELECT * FROM \"tblTasks\"";
odbcDA_TaskActivities.SelectCommand = cmd;
odbcDA_TaskActivities.Fill(dsTaskActivities, "Tasks");
cmd.CommandText = "SELECT * FROM \"tblActivity\"";
odbcDA_TaskActivities.SelectCommand = cmd;
odbcDA_TaskActivities.Fill(dsTaskActivities, "Activity");

It compiles fine but crashes on the last line with this message:

An unhandled exception of type 'System.NullReferenceException' occurred in
system.data.dll
Additional information: Object reference not set to an instance of an
object.

What's really confusing is why it will run through
odbcDA_TaskActivities.Fill(dsTaskActivities, "Tasks");
without complaint but crash on
odbcDA_TaskActivities.Fill(dsTaskActivities, "Activity");

I've read the Help text on these subjects and patterned this code after one
of the examples. Clearly I'm missing some fundamental information about how
these objects relate to one another. Would anyone like to lend some
elucidation?
Nov 17 '05 #1
5 1167

"Christopher Weaver" <we*****@verizon.net> wrote in message
news:uS**************@TK2MSFTNGP15.phx.gbl...
I'm confused about the relationships between these objects. I've written
this:
What's really confusing is why it will run through
odbcDA_TaskActivities.Fill(dsTaskActivities, "Tasks");
without complaint but crash on
odbcDA_TaskActivities.Fill(dsTaskActivities, "Activity");

Make sure the SQL string that you've passed into the command to fill the
"Activity" table is valid.
BTW, you don't need to use the lines: DataTable dtTask = dsTaskActivities.Tables.Add("Tasks");
DataTable dtActivity = dsTaskActivities.Tables.Add("Activity");

Using the dataadapter Fill function will create the tables if they don't
exist already.
Nov 17 '05 #2
Thank you Brian.

I have tried changing the SQL string by simply replacing the table name with
another, and it works just fine. Actually, the only difference between the
portion of the code that succeeds and that that fails is the name of the
table. tblActivity is the actual name of the table; I've copied and pasted
it in. Any other ideas here?

In regard to the Tables.Add lines, I was attempting to specify the names of
the tables. Is there another way of doing so, or is there any need to
bother?
"BrianGlacain" <bg******@yahoo.com> wrote in message
news:O8**************@TK2MSFTNGP14.phx.gbl...

"Christopher Weaver" <we*****@verizon.net> wrote in message
news:uS**************@TK2MSFTNGP15.phx.gbl...
I'm confused about the relationships between these objects. I've written
this:

What's really confusing is why it will run through
odbcDA_TaskActivities.Fill(dsTaskActivities, "Tasks");
without complaint but crash on
odbcDA_TaskActivities.Fill(dsTaskActivities, "Activity");


Make sure the SQL string that you've passed into the command to fill the
"Activity" table is valid.
BTW, you don't need to use the lines:
DataTable dtTask = dsTaskActivities.Tables.Add("Tasks");
DataTable dtActivity = dsTaskActivities.Tables.Add("Activity");

Using the dataadapter Fill function will create the tables if they don't
exist already.

Nov 17 '05 #3

"Christopher Weaver" <we*****@verizon.net> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Thank you Brian.

I have tried changing the SQL string by simply replacing the table name
with another, and it works just fine. Actually, the only difference
between the portion of the code that succeeds and that that fails is the
name of the table. tblActivity is the actual name of the table; I've
copied and pasted it in. Any other ideas here?
It sounds like it's related to the database end of things. What database are
you using? Make sure you have permission to execute the SQL statements
against the table.
In regard to the Tables.Add lines, I was attempting to specify the names
of the tables. Is there another way of doing so, or is there any need to
bother?


It depends on what you plan on doing. The Fill command of the DataAdapter
creates the tables using the names you've specified. If you need to refer to
the tables directly, you could do something like:
MessageBox.Show(dsTaskActivities.Tables["Tasks"].Rows.Count.ToString())
If you want a DataTable variable you could use:
DataTable dtTask = dsTaskActivities.Tables["Tasks"];
Saying that, the way you had it will also work.

Nov 17 '05 #4
Thanks Brian.

I'm connecting to InterBase 7.5 as the owner and administrator of the
database. I have all rights granted.

I'm inclined to agree that it's a back end thing. Unfortunately, I think
it's a back end / front end relationship thing because I've had no trouble
selecting and updating the same table in an app written in Delphi.

If you think of anything else, please let me know. I will keep an eye on
this thread for a while! If I figure it out I will post a message for any
other soul struggling with anything similar.


"BrianGlacain" <bg******@yahoo.com> wrote in message
news:up**************@TK2MSFTNGP15.phx.gbl...

"Christopher Weaver" <we*****@verizon.net> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Thank you Brian.

I have tried changing the SQL string by simply replacing the table name
with another, and it works just fine. Actually, the only difference
between the portion of the code that succeeds and that that fails is the
name of the table. tblActivity is the actual name of the table; I've
copied and pasted it in. Any other ideas here?


It sounds like it's related to the database end of things. What database
are you using? Make sure you have permission to execute the SQL statements
against the table.
In regard to the Tables.Add lines, I was attempting to specify the names
of the tables. Is there another way of doing so, or is there any need to
bother?


It depends on what you plan on doing. The Fill command of the DataAdapter
creates the tables using the names you've specified. If you need to refer
to the tables directly, you could do something like:
MessageBox.Show(dsTaskActivities.Tables["Tasks"].Rows.Count.ToString())
If you want a DataTable variable you could use:
DataTable dtTask = dsTaskActivities.Tables["Tasks"];
Saying that, the way you had it will also work.


Nov 17 '05 #5
Here's the answer, for anyone wondering. Some of the records on the back
end are corrupt in some way, or otherwise unfit for transmission through the
ODBC connection that I'm using. I can view them through a console app that
was written specifically for the back end (InterBase 7.5), but VS, using the
ODBC driver that came with InterBase has a problem with them.

So far I've found two offensive records, and in both cases, when I deleted
the contents of a VARCHAR 255 field, the problem was gone. I couldn't see
anything within those fields that looked suspicious, but something was
amiss.

Thanks for your help.
"Christopher Weaver" <we*****@verizon.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Thanks Brian.

I'm connecting to InterBase 7.5 as the owner and administrator of the
database. I have all rights granted.

I'm inclined to agree that it's a back end thing. Unfortunately, I think
it's a back end / front end relationship thing because I've had no trouble
selecting and updating the same table in an app written in Delphi.

If you think of anything else, please let me know. I will keep an eye on
this thread for a while! If I figure it out I will post a message for any
other soul struggling with anything similar.


"BrianGlacain" <bg******@yahoo.com> wrote in message
news:up**************@TK2MSFTNGP15.phx.gbl...

"Christopher Weaver" <we*****@verizon.net> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Thank you Brian.

I have tried changing the SQL string by simply replacing the table name
with another, and it works just fine. Actually, the only difference
between the portion of the code that succeeds and that that fails is the
name of the table. tblActivity is the actual name of the table; I've
copied and pasted it in. Any other ideas here?


It sounds like it's related to the database end of things. What database
are you using? Make sure you have permission to execute the SQL
statements against the table.
In regard to the Tables.Add lines, I was attempting to specify the names
of the tables. Is there another way of doing so, or is there any need
to bother?


It depends on what you plan on doing. The Fill command of the DataAdapter
creates the tables using the names you've specified. If you need to refer
to the tables directly, you could do something like:
MessageBox.Show(dsTaskActivities.Tables["Tasks"].Rows.Count.ToString())
If you want a DataTable variable you could use:
DataTable dtTask = dsTaskActivities.Tables["Tasks"];
Saying that, the way you had it will also work.



Nov 17 '05 #6

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

Similar topics

0
by: William Ryan | last post by:
At the risk of sounding like a Big 5 consultant, "It depends". 1) Strongly typed datasets rock, they are faster than untyped, use intellisense... but your reason for wanting to use them is...
45
by: cody | last post by:
I've seen an Introduction on ADO.NET with its Datasets on .NET TV and Iam now wondering how it is realized/used in real world applications. I don't believe that one would create a dataset and add...
2
by: malcolm | last post by:
Hello, We have a robust (.NET 1.1 c# winforms) client-server application that utilizes many typed DataSets, typed DataTables and typed DataRows. Our application is a series of windows and popup...
2
by: Adam Clauss | last post by:
Alright, as much as I've done CSharp, I've done very little with databases with it. So I'm just kind of messing around with, learning how it works. I am using the ADO.NET adapter provided with...
11
by: Peter M. | last post by:
Hi all, I'm currently designing an n-tier application and have some doubts about my design. I have created a Data Access layer which connects to the database (SQL Server) and performs Select,...
3
by: cj | last post by:
I've used datatables and datasets before. Datasets being able to hold more than one table and datatables being only one table. My mind keeps coming up with recordsets. I can't remember how they...
16
by: Luqman | last post by:
Is it recommended to use datasets in ASP.Net 2.0 / VS.Net 2005 ? Best Regards, Luqman
0
balabaster
by: balabaster | last post by:
I have my SQL database with the following structure: Table1( PrimaryKey Int Not Null Identity(1, 1) Primary Key, TextData Varchar(50) Not Null ) Table2( PrimaryKey Int Not...
12
by: BillE | last post by:
I'm trying to decide if it is better to use typed datasets or business objects, so I would appreciate any thoughts from someone with more experience. When I use a business object to populate a...
1
by: Mark Baldwin | last post by:
Steven Thanks for your reply, however the typed datasets are defined in the web service and there seems to way to open the partial class code window - double clicking on the design surface does...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.