List Info

Thread: DataTable




DataTable
country flaguser name
United States
2007-10-02 19:10:44

Guys

A buddy of mine is working with .Net (poor guy --
hehe, sorry, I'm a VB6 kinda guy). He has populated
a datatable.. it was initialized with the following...

Dim MyDT as New DataTable

It is then populated using...

Dim dataadapter As New SqlDataAdapter(testCommmand)
dataadapter.Fill(MyDT)

I've left out the connection code.. assume that MyDT
is populated. Here is the question:

How would he read the value of record 1, field 1,
and stick it in a variable v1. Then, how would
he advance to record 2, field 1, and do same?

Using Access and VB6, I'd do something like this:

Dim MyRS as Recordset
<code to populate the table>
MyRS.MoveFirst
v1 = MyRS(";MyField&quot;)
MyRS.MoveNext
v1 = MyRS(";MyField&quot;)

Pretty easy with Access and VB6.
How does one do that in .Net?

Spoo

__._,_.___
.

__,_._,___
Re: DataTable
country flaguser name
United States
2007-10-03 14:49:26

DataTable has a propierty called Rows.

Imagine you got this:

oTable as your table already filled with the data. So you do this:

oTable.Rows(0)(0) this will give you the value of the Row 1 Colum 1
oTable.Rows(1)(0) this will give you the value of the Row 2 Colum 1
oTable.Rows(1)(2) this will give you the value of the Row 2 Colum 2

and so On...

It's like a two-dimension array the 1st array gives you the Rows and the 2nd
one the Colums

Hope this help.-

On 10/2/07, spooboy54 < spooboy54%40yahoo.com">spooboy54yahoo.com> wrote:

> Guys
>;
> A buddy of mine is working with .Net (poor guy --
> hehe, sorry, I'm a VB6 kinda guy). He has populated
> a datatable.. it was initialized with the following...
>
> Dim MyDT as New DataTable
>
&gt; It is then populated using...
>
>; Dim dataadapter As New SqlDataAdapter(testCommmand)
> dataadapter.Fill(MyDT)
>
> I've left out the connection code.. assume that MyDT
>; is populated. Here is the question:
>
&gt; How would he read the value of record 1, field 1,
> and stick it in a variable v1. Then, how would
&gt; he advance to record 2, field 1, and do same?
&gt;
> Using Access and VB6, I'd do something like this:
&gt;
> Dim MyRS as Recordset
> <code to populate the table>
> MyRS.MoveFirst
> v1 = MyRS(";MyField&quot;)
>; MyRS.MoveNext
> v1 = MyRS(";MyField&quot;)
>;
> Pretty easy with Access and VB6.
>; How does one do that in .Net?
&gt;
> Spoo
>;
>
>

[Non-text portions of this message have been removed]

__._,_.___
.

__,_._,___
Re: DataTable
country flaguser name
United States
2007-10-04 03:00:25

Ensure that the table has rows:

If MyDT.Rows.Count <> 0 Then
'To access the first row and first column item:
YourVariable = MyDT.Rows(0).Item(0)
'To access the first row and the second column item:
YourVariable = MyDT.Rows(0).Item(1)
'To access the second row and the second column item:
YourVariable = MyDT.Rows(1).Item(1)

'and so on...

End If

spooboy54 < spooboy54%40yahoo.com">spooboy54yahoo.com> wrote:
Guys

A buddy of mine is working with .Net (poor guy --
hehe, sorry, I'm a VB6 kinda guy). He has populated
a datatable.. it was initialized with the following...

Dim MyDT as New DataTable

It is then populated using...

Dim dataadapter As New SqlDataAdapter(testCommmand)
dataadapter.Fill(MyDT)

I've left out the connection code.. assume that MyDT
is populated. Here is the question:

How would he read the value of record 1, field 1,
and stick it in a variable v1. Then, how would
he advance to record 2, field 1, and do same?

Using Access and VB6, I'd do something like this:

Dim MyRS as Recordset
<code to populate the table>
MyRS.MoveFirst
v1 = MyRS(";MyField&quot;)
MyRS.MoveNext
v1 = MyRS(";MyField&quot;)

Pretty easy with Access and VB6.
How does one do that in .Net?

Spoo

---------------------------------

A smile is the light in your window that tells others that there is a caring, sharing person inside.
Keep SMILING
---------------------------------

Eze Stephen O.
Systemtech Services Ltd.
Mobile: +2348037227608

Blog: View my diary

---------------------------------
Don't let your dream ride pass you by. Make it a reality with Yahoo! Autos.

[Non-text portions of this message have been removed]

__._,_.___
.

__,_._,___
[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )