PC Review


Reply
Thread Tools Rate Thread

accessing the dataset tables, by name and not by index

 
 
roni
Guest
Posts: n/a
 
      13th Jul 2005
hi.

i created a command that get 2 tables from db.

when try to access the tables in the dataset , i can't access the tables by
their names(by their original name from db ),only by index.

is there a way to access them by name ? (meaning the dataset will automatic
will set the real name of the db table ).


 
Reply With Quote
 
 
 
 
=?Utf-8?B?RWx0b24gVw==?=
Guest
Posts: n/a
 
      13th Jul 2005
Hi there,

When you use DataAdapter to fill a DataSet, unless you give specified table
name, it assigns default table name, ‘Table’. For example, in following code

SqlDataAdapter dap = new SqlDataAdapter(“Select * From table_one; Select *
From table_two”, CONNECTION_STRING);
DataSet ds = new DataSet();
Dap.Fill(ds);

Two tables are in ds, their table names are ‘Table’ and ‘Table1’ respectively.

Or

dap.Fill(ds, “Table_One”);

You have table name ‘Table_One’ for the first table and ‘Table_One1’ for
second table.

HTH

Elton Wang
(E-Mail Removed)


"roni" wrote:

> hi.
>
> i created a command that get 2 tables from db.
>
> when try to access the tables in the dataset , i can't access the tables by
> their names(by their original name from db ),only by index.
>
> is there a way to access them by name ? (meaning the dataset will automatic
> will set the real name of the db table ).
>
>
>

 
Reply With Quote
 
Frank Loizzi
Guest
Posts: n/a
 
      13th Jul 2005
Am Wed, 13 Jul 2005 13:03:58 +0200 schrieb roni:

> i created a command that get 2 tables from db.
>
> when try to access the tables in the dataset , i can't access the tables by
> their names(by their original name from db ),only by index.
>
> is there a way to access them by name ? (meaning the dataset will automatic
> will set the real name of the db table ).


There are few ways to access the tables of your database. Depending what
kind of dataset you use.

myDataset.Tables["myTable"]
myDataset.Tables[0]

myDataset.myTable //typed dataset
myDataset.myTable[0][1] //typed dataset (row and column access)

You must add a table mapping when you fill the data adapter.

This is C# syntax.

Mfg

Frank Loizzi
Germany
 
Reply With Quote
 
Bernie Yaeger
Guest
Posts: n/a
 
      13th Jul 2005
Hi Roni,

You can refer to a table within a dataset through its pseudonym, which may
be established when you build your dataset. Here's an example (oconn is the
connection object):
Dim ocmd As New SqlCommand("select * from evcodes", oconn)

Dim oda As New SqlDataAdapter(ocmd)

Dim ods As New DataSet("Event Codes")

Try

oconn.Open()

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

oda.Fill(ods, "Event Codes")

Dim irow As DataRow

Dim colpk(0) As DataColumn

colpk(0) = ods.Tables(0).Columns("eventcd")

colpk(0) = ods.Tables("Event Codes").Columns("eventcd")

' either of the two lines above will work

HTH,

Bernie Yaeger



"roni" <(E-Mail Removed)> wrote in message
news:db2oao$rur$(E-Mail Removed)...
> hi.
>
> i created a command that get 2 tables from db.
>
> when try to access the tables in the dataset , i can't access the tables
> by
> their names(by their original name from db ),only by index.
>
> is there a way to access them by name ? (meaning the dataset will
> automatic
> will set the real name of the db table ).
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing tables inside a dataset to display in a datalist =?Utf-8?B?TW9vampvbw==?= Microsoft ADO .NET 1 18th Jul 2005 07:05 PM
Accessing data in multiple tables within a dataset =?Utf-8?B?TW9vampvbw==?= Microsoft C# .NET 1 18th Jul 2005 04:42 PM
accessing the dataset tables, by name and not by index Armin Zingler Microsoft VB .NET 2 14th Jul 2005 03:45 AM
VB 2005 Row index in datagridview <> row index in dataset Robert Koller Microsoft VB .NET 7 2nd Jun 2005 02:52 AM
Accessing ArrayList index by a key not an index number Jack Addington Microsoft C# .NET 5 4th Nov 2004 05:27 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:18 PM.