Problems adding a calculated field to an existing dataset.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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?
 
B.

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

It should be easy

Cor
 
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.
 
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();

}
 
Back
Top