Manipulating data on input w/ TableAdapter & Dataset.

  • Thread starter Thread starter Mike Edgewood
  • Start date Start date
M

Mike Edgewood

I know this is easier to do with a datareader and a listview, but can
it be done with a tableadapter and a dataset?

I want to manipulate the data prior to it reaching the dataset, For
instance, data is stored as Firstname and Lastname and sometimes there
will be no firstname, so appending a comma in this instance looks
stupid. So I need to check if firstname exists then return lastname &
", " & firstname or if not exist, just return lastname.

I was trying to do this with an IIF statement in the SQL code but it
wouldn't run saying it was an unrecognized command although it is
described in the BOL documentation for SQL Server 2000.

I also tried to do it with partial class of the dataset. First on
RowChanging, e.row = "processed data", error = cannot change proposed
value. Next on RowChanged, also met with error.

Any ideas, or is this not meant to be?
 
you need to take a look at the documentation for sql server. It has a lot of
sql function that can be used in the sql statement. One in particular is
IsNull, which can allow you to do these concatenations safely.

You can also have calculated columns in the database by setting the
Expression property of a column What is valid in the expression is fully
documented, and you should be able to construct an expression to create the
correct string.
 
Mike,

If the solution from Marina is for whatever reason not the one for you, than
you can use extra (expression) columns in your dataset/datatable.

It is not what you ask, however full AdoNet, while your question is now more
related to the database that you are using. The used SQL dialect should have
a feature for what you ask.

I hope this gives an idea.

Cor
 
I'm afraid I was unsuccessful with my previous attempts on a calculated
column. That is where I started with this mess, actually.

Perhaps you can help shed some light where I am failing. How could you
write an expression for the aforementioned problem? In the mean time,
I'll try to find some better documentation on the calculated column.
 
I believe the resolution I'm needing goes beyond what an expression
column can handle. So I was wondering if there was another way to
manipulate the data prior to it reaching a datatable. Partial
classes, perhaps?

Where I am working it is common (and allowed) to enter just a state and
a zip code or perhaps just a zipcode. So when I fill a readonly table
I want to know whether or not to append a comma to my citystate field.


Data field possibilities

city: "Parsippany"
state "NJ"
zip "07054"

Desired output "Parsippany, NJ"

city: ""
State: "NJ"
zip: "07054"
Desired output - "NJ" (not ", NJ")

city:
state:
zip: 07054
desired output - "" (not ",")

Is it doable?
 
Back
Top