Row filtering

G

Guest

Hi all,
I am having a dataset which is Reading from the XML file. The Dataset has a
table Users with Scheema (US_ID, US_Name). I am attempting to add new user to
this table. for this I want to fetch the max US_ID , increment by One and add
to table
The code is
maxID = dsUser.Tables(0).Select("US_ID=MAX(US_ID)")
The issue I am facing is that I am not getting proper maxID as US_ID is
interpreted as char while reading.
I also tried using the cast expression but I m getting syntax error.

any suggestion will be highly appreciated...

Cheers,
siaj
 
K

Kevin Spencer

Have you tried converting it to a number?

Let me explain the difference between casting and converting. Casting is
done when a data type IS the type being cast to. IOW, the data type is
either the target type or it is inherited from the target type. You can cast
a System.Web.UI.Page as a System.Web.UI.Control because it inherits
System.Web.UI.Control. It IS a System.Web.UI.Control.

Converting is done when the type IS NOT the same data type as the target
type. Strings, for example, can not be CAST as integers; they are not in any
sense integers. However, they can, if they are strings of numbers, be
CONVERTED to integers.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
G

Guest

Thanks for the Reply but casting works in SQL server atleast
for eg :
USE foodMart
GO
SELECT * FROM salary WHERE employee_ID =(SELECT MAX (CAST(employee_ID as
int)) FROM salary)

Although I had tried using convert also but it does not helps ...

Cheers,
siaj
 
K

Kevin Spencer

Thanks for the Reply but casting works in SQL server atleast

Casting works for fishing too, but I wouldn't try to use that sort of
casting in a .Net application.

Just because the same term is used, and even has a -similar- meaning in 2
different software packages doesn't mean that it IS the same. Using CAST in
SQL Server is NOT the same as casting in a .Net app. Apples and oranges are
both fruit, but they sure don't taste the same!

Re-read my explanation of casting and converting in .Net.

I would attempt to help you more, but you've provided no new information.
All you've said is that you "tried" some unknown thing ("Using Convert" -
whatever that means in specific terms), and that, for some reason, "it does
not helps." For example, if you went to an auto parts store, and told them
you needed a carbeurator, which they sold to you, and you went home and
tried to install it, and it didn't work, they would want to know HOW you
tried to install it, and what specifically happened when you did (how did
your car behave?). For example, you might have tried to bolt it to your
steering wheel, for all they know.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
G

Guest

Thanks for ur time and enlightening on fishing and AutoParts ... I was
looking for some enlightening on some .net Issue..
Meanwhile I tried the Rowfiltering as
axIDRow = dsUser.Tables(0).Select("US_ID=(SELECT MAX (CONVERT(int,US_ID))
FROM Users)")

It gives Error
Syntax error: Missing operand after 'MAX' operator.

cheers,
siaj
 
K

Kevin Spencer

Thanks for ur time and enlightening on fishing and AutoParts ... I was
looking for some enlightening on some .net Issue..

It's a shame that you thought I was talking about fishing and auto parts. I
was giving you enlightenment on .Net issues by using analogies, but
apparently you missed it.

In fact, you MUST have missed it, because you're still trying to treat .Net
executable code and classes as if they were SQL Server. Although the
Expression used in a DataTable.Select() method is a string, just like SQL,
it is NOT SQL. You just tried to bolt your new carbeurator to the steering
column. You're trying to make apple sauce out of orange juice.

The following reference concerning the Expression property of a DataColumn
is the same rules as the expression you use with the Select() method of a
DataTable (in fact I found it by looking up the Select() method of a
DataTable), so don't go there and assume I am pointing you in the wrong
direction:

http://msdn.microsoft.com/library/d...fsystemdatadatacolumnclassexpressiontopic.asp

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
G

Guest

Kevin, I appreciate ur helping attitude and I have gone thru the links u
provided but the analogies and words like "shame" were definately not in
good taste for aspirants of .Net. Phrases like this many times takes out the
essence out of the good solutions.
Usergroups are meant to help and encourage people not bashing and shaming
people....

Thanks for all....
siaj
 
K

Kevin Spencer

I wasn't bashing you, but since you come from a different country you may
have thought I was. "I'ts a shame" is an English expression of "it's too
bad".

Here's an idea. Why don't you get the Max by looping through the DataTable?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top