473,769 Members | 2,062 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataAdapters, DataSets, DataTables

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

DataSet dsTaskActivitie s = new DataSet("TA");
DataTable dtTask = dsTaskActivitie s.Tables.Add("T asks");
DataTable dtActivity = dsTaskActivitie s.Tables.Add("A ctivity");
OdbcCommand cmd = new OdbcCommand();
cmd.Connection = odbcIB;
cmd.CommandText = "SELECT * FROM \"tblTasks\" ";
odbcDA_TaskActi vities.SelectCo mmand = cmd;
odbcDA_TaskActi vities.Fill(dsT askActivities, "Tasks");
cmd.CommandText = "SELECT * FROM \"tblActivity\" ";
odbcDA_TaskActi vities.SelectCo mmand = cmd;
odbcDA_TaskActi vities.Fill(dsT askActivities, "Activity") ;

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

An unhandled exception of type 'System.NullRef erenceException ' 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_TaskActi vities.Fill(dsT askActivities, "Tasks");
without complaint but crash on
odbcDA_TaskActi vities.Fill(dsT askActivities, "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 1181

"Christophe r Weaver" <we*****@verizo n.net> wrote in message
news:uS******** ******@TK2MSFTN GP15.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_TaskActi vities.Fill(dsT askActivities, "Tasks");
without complaint but crash on
odbcDA_TaskActi vities.Fill(dsT askActivities, "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 = dsTaskActivitie s.Tables.Add("T asks");
DataTable dtActivity = dsTaskActivitie s.Tables.Add("A ctivity");

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?
"BrianGlaca in" <bg******@yahoo .com> wrote in message
news:O8******** ******@TK2MSFTN GP14.phx.gbl...

"Christophe r Weaver" <we*****@verizo n.net> wrote in message
news:uS******** ******@TK2MSFTN GP15.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_TaskActi vities.Fill(dsT askActivities, "Tasks");
without complaint but crash on
odbcDA_TaskActi vities.Fill(dsT askActivities, "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 = dsTaskActivitie s.Tables.Add("T asks");
DataTable dtActivity = dsTaskActivitie s.Tables.Add("A ctivity");

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

Nov 17 '05 #3

"Christophe r Weaver" <we*****@verizo n.net> wrote in message
news:%2******** ********@TK2MSF TNGP15.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 (dsTaskActiviti es.Tables["Tasks"].Rows.Count.ToS tring())
If you want a DataTable variable you could use:
DataTable dtTask = dsTaskActivitie s.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.


"BrianGlaca in" <bg******@yahoo .com> wrote in message
news:up******** ******@TK2MSFTN GP15.phx.gbl...

"Christophe r Weaver" <we*****@verizo n.net> wrote in message
news:%2******** ********@TK2MSF TNGP15.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 (dsTaskActiviti es.Tables["Tasks"].Rows.Count.ToS tring())
If you want a DataTable variable you could use:
DataTable dtTask = dsTaskActivitie s.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.
"Christophe r Weaver" <we*****@verizo n.net> wrote in message
news:%2******** ********@TK2MSF TNGP10.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.


"BrianGlaca in" <bg******@yahoo .com> wrote in message
news:up******** ******@TK2MSFTN GP15.phx.gbl...

"Christophe r Weaver" <we*****@verizo n.net> wrote in message
news:%2******** ********@TK2MSF TNGP15.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 (dsTaskActiviti es.Tables["Tasks"].Rows.Count.ToS tring())
If you want a DataTable variable you could use:
DataTable dtTask = dsTaskActivitie s.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
2693
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 important. I use them every day of my life, but I also don't use them every day of my life and there are reasons for both. 2) How much of your process is dependent on reads vs.
45
2451
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 relations to it and so on for every table in the application, this would be a real mess and this has nothing to do with OOP. Normally, would would create a class Customer, a class Invoices, Positions, Articles and so on. But how can this be...
2
2317
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 windows where you can edit information and data, nothing out of the ordinary. I estimate we have something like 50 to 100 tables and/or views in our database each of which map to one strongly typed DataTable. Now we have some odd 20 to 30 typed...
2
1357
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 MySQL in a very simple web application. I have the connection, data adapter, and typed datasets created. In response to a button submit, I perform the following: accountsDataAdapter.Fill(accountsDS1); Label_Accounts.Text =...
11
2570
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, update, delete and inserts. I use dataset objects to pass data to and from the DAL. In my GUI (windows forms), I use databinding to bind controls to a datatable
3
1589
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 fit into the picture. I'm going to be reading some records from a table in a sql db.
16
1938
by: Luqman | last post by:
Is it recommended to use datasets in ASP.Net 2.0 / VS.Net 2005 ? Best Regards, Luqman
0
964
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 Null(Identity(1, 1) Primary Key, ForeignKey Int Not Null Foreign Key References Table1(PrimaryKey),
12
3603
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 gridview, for example, I loop through a datareader, populating an array list with instances of a custom class in the middle tier, and then send the array list up to the presentation layer and bind the gridview to it. If I use a typed dataset, I...
1
1785
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 nothing. I can do this in the client for a client specific dataset, but not in the web service. -- Best regards Mark Baldwin
0
10049
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8872
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7410
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5307
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3564
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.