p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

aspx thread: Asp.Net - maybe more different then said then Asp.


Message #1 by SARGHI Mircea Ionut <syms@i...> on Fri, 5 Jul 2002 15:25:02 +0300 (EEST)
Hi all,

I have just started migrating from Asp to Asp.Net. I thought it should not 
be that hard. Anyway, i see now that using the same thinking as i did in 
pure Asp does not help.

Fox example, could someone clear this for me.

Let's say we have a table [products] and i want to access the value from 
product_no. How is that done using Asp.Net. I am creating the connection, 
the data adapter, and dataset. Now if i want to list all the values 
returned by the dataset in datagrid, ok...easy, but how does a function 
that returns a value of a field(just the value, this case, integer) look 
like in C#?

Thanks.

Message #2 by "Dave Buckner" <Dave@N...> on Fri, 5 Jul 2002 11:01:56 -0500
use a Default view on your table in the dataset. e.g.

dim oDV as DefaultView = oDS.Tables(0).DefaultView
oDV.Filter

I can't remember the 100% syntax for the .Filter call, but thats how it can
be done.

Regards,
Dave

-----Original Message-----
From: SARGHI Mircea Ionut [mailto:syms@i...]
Sent: Friday, July 05, 2002 7:25 AM
To: ASP+
Subject: [aspx] Asp.Net - maybe more different then said then Asp.



Hi all,

I have just started migrating from Asp to Asp.Net. I thought it should not
be that hard. Anyway, i see now that using the same thinking as i did in
pure Asp does not help.

Fox example, could someone clear this for me.

Let's say we have a table [products] and i want to access the value from
product_no. How is that done using Asp.Net. I am creating the connection,
the data adapter, and dataset. Now if i want to list all the values
returned by the dataset in datagrid, ok...easy, but how does a function
that returns a value of a field(just the value, this case, integer) look
like in C#?

Thanks.





Message #3 by "Garland Frye" <gfrye@s...> on Fri, 5 Jul 2002 11:35:19 -0500
You've got a few choices here. However the first thing you must come to grip
with is from the dataset, to individual datafields are members of a
collection. DataSet is a collection of DataTables. Each DataTable is a
collection of Rows, Each Row is a collection of DataColumns. If you want to
get to one atomic field value, from one row, then do something like this...

==This code assumes all the plumbing to fill the dataset is in
place=========

indexVar = 1;    //or two, or three, or whatever row you want
int n = myDataSet.Tables["products"].Rows[indexVar]["product_no"];

============Done=====================================

So it's just simply a matter of indexing all the way to your value, these
collections implement IList, and IDictionary, so you can index into them by
name, or by index.

If you would like to get a list of values for a specific column in a row,
you can do something like this...

=================List of values============================
DataView dv;
dv = myDataSet.Tables["products"].Select("product_no");    //just like a SQL
dv.Filter("product_no > 0");    //just like a SQL expressions
foreach (DataRowView drv in dv)
{
    //do something with drv["product_no"]
}
=================END OF SOURCE=========================

So there are several ways to get to your desired data, out of all this
garble, you can surely find something that will help.

Thanks,
Garland
"SARGHI Mircea Ionut" <syms@i...> wrote in message
news:190888@a...
>
>
> Hi all,
>
> I have just started migrating from Asp to Asp.Net. I thought it should not
> be that hard. Anyway, i see now that using the same thinking as i did in
> pure Asp does not help.
>
> Fox example, could someone clear this for me.
>
> Let's say we have a table [products] and i want to access the value from
> product_no. How is that done using Asp.Net. I am creating the connection,
> the data adapter, and dataset. Now if i want to list all the values
> returned by the dataset in datagrid, ok...easy, but how does a function
> that returns a value of a field(just the value, this case, integer) look
> like in C#?
>
> Thanks.
>
>
>


Message #4 by "sydney frederick-osborne" <sydney@i...> on Sat, 6 Jul 2002 00:23:55
Instead of using the heavyweight data adapter and dataset, you can use a 
SqlCommand and SqlDataReader, then loop through the SqlDataReader record 
to get values.

But even easier for a single value, there is the ExecuteScalar method (of 
the SqlConnection, I think, though it may be the SqlCommand) - given an 
SQL statement that just returns a single value, this is what you want.

Sydney

> 
Hi all,

I have just started migrating from Asp to Asp.Net. I thought it should not 
be that hard. Anyway, i see now that using the same thinking as i did in 
pure Asp does not help.

Fox example, could someone clear this for me.

Let's say we have a table [products] and i want to access the value from 
product_no. How is that done using Asp.Net. I am creating the connection, 
the data adapter, and dataset. Now if i want to list all the values 
returned by the dataset in datagrid, ok...easy, but how does a function 
that returns a value of a field(just the value, this case, integer) look 
like in C#?

Thanks.


  Return to Index