Home All Groups Group Topic Archive Search About

Problems adding a calculated field to an existing dataset.

Author
7 Nov 2007 7:34 PM
B. Chernick
I'm doing a project in Winforms VB/Dot 2.0.  I have an existing xsd. 

What I would like to do is add a calculated field to a table.  This column
would simply be a concatenation of 2 other fields, both fixed length char
fields, (The expression field is simply field1name + field2name). 

I've never tried this before and I cannot get this to work.  The column
declaration is coming through but every value is a null, even though the
other 2 fields have normal (non-null) values. 

What might I be forgetting?

Author
8 Nov 2007 5:48 AM
Cor Ligthert[MVP]
B.

Will you show the complete line of  code about the expression?

It should be easy

Cor
Author
8 Nov 2007 4:29 PM
B. Chernick
Actually there was no code. I was using the xsd designer only.  I went in to
the table, added a column, and then went into the column properties and set
the expression equal to columnname1 + columnname2.  If I remember correctly I
then tried using it both with and without the calculated column name in the
sql query.  Nothing worked. 

However I did find a working solution.  I cleared the expression and I then
changed the sql query to include the calculated field as an alias --
(column1name + column2name) as calculatedColumnName.  This seems to work
perfectly and doesn't interfer with any code that uses other queries off this
table.

Thanks.

Show quote
"Cor Ligthert[MVP]" wrote:

> B.
>
> Will you show the complete line of  code about the expression?
>
> It should be easy
>
> Cor
Author
19 Nov 2007 2:23 PM
W.G. Ryan
B:

Here's the code I used: I have a typed dataset named Customers with a
FirstName and LastName Field. I added FullNameForward that just does
[FirstName] + ' ' + [LastName] and the FullNameWithComma that does
[LastName]+ ', ' + [FirstName]  as the respective formulas.  The results are
as you'd expect.  Hope this helps - but if not please let me know and we'll
make it happen.



static void Main(string[] args)

{

CalcFields ds = new CalcFields();

CalcFields.CustomersRow row = ds.Customers.NewCustomersRow();

row.FirstName = "William";

row.LastName = "Ryan";

ds.Customers.Rows.Add(row);

CalcFields.CustomersRow row2 = ds.Customers.NewCustomersRow();

row2.FirstName = "B";

row2.LastName = "Chernick";

ds.Customers.Rows.Add(row2);

foreach (CalcFields.CustomersRow rows in ds.Customers.Rows)

{

Console.WriteLine("FirstName: " + rows.FirstName);

Console.WriteLine("LastName: " + rows.LastName);

Console.WriteLine("FullName: " + rows.FullNameForward);

Console.WriteLine("FullName With Comma: " + rows.FullNameWithComma);

}

Console.ReadLine();

}





Show quote
"B. Chernick" <BChern***@discussions.microsoft.com> wrote in message
news:847CDBA7-C694-4C3E-85D6-42C0B13F5D0B@microsoft.com...
> I'm doing a project in Winforms VB/Dot 2.0.  I have an existing xsd.
>
> What I would like to do is add a calculated field to a table.  This column
> would simply be a concatenation of 2 other fields, both fixed length char
> fields, (The expression field is simply field1name + field2name).
>
> I've never tried this before and I cannot get this to work.  The column
> declaration is coming through but every value is a null, even though the
> other 2 fields have normal (non-null) values.
>
> What might I be forgetting?

AddThis Social Bookmark Button