How do I add a new column cominging 2 string and a int column ?

G

Guest

Is there any way to create a new column in a dataset table from 2 string
column and a int column? I got an error "expecting string" from my code
below. Any help would be appreciated.

DataColumn scc1 = new
DataColumn("CodeLength",Type.GetType("System.String"));
scc1.Expression = "iif(len(CycleLength) > 0,CycleCode + ' - ' +
CycleLength,CycleCode)";
dsSchTables.Tables["ServiceCycle"].Columns.Add(scc1);
dsSchTables.AcceptChanges();

DataColumn scc2 = new
DataColumn("CodeLengthUnit",Type.GetType("System.String"));
scc1.Expression = "iif(len(CycleUnit) > 0,CodeLength + ' - ' +
CycleUnit,CodeLength)";
dsSchTables.Tables["ServiceCycle"].Columns.Add(scc2);
dsSchTables.AcceptChanges();
 
C

Cor Ligthert [MVP]

Alpha,

I am curious about the meaning of the + '-' + in your expression?

Cor
 
G

Guest

That is just part of the string that I would like to display to the user to
make it easier to read the information that are consist of a Code, followed
by a '_' and the the length and unit. It would read something like this in
the combox 3k - 3000 miles


Cor Ligthert said:
Alpha,

I am curious about the meaning of the + '-' + in your expression?

Cor

Alpha said:
Is there any way to create a new column in a dataset table from 2 string
column and a int column? I got an error "expecting string" from my code
below. Any help would be appreciated.

DataColumn scc1 = new
DataColumn("CodeLength",Type.GetType("System.String"));
scc1.Expression = "iif(len(CycleLength) > 0,CycleCode + ' - ' +
CycleLength,CycleCode)";
dsSchTables.Tables["ServiceCycle"].Columns.Add(scc1);
dsSchTables.AcceptChanges();

DataColumn scc2 = new
DataColumn("CodeLengthUnit",Type.GetType("System.String"));
scc1.Expression = "iif(len(CycleUnit) > 0,CodeLength + ' - ' +
CycleUnit,CodeLength)";
dsSchTables.Tables["ServiceCycle"].Columns.Add(scc2);
dsSchTables.AcceptChanges();
 
C

Cor Ligthert [MVP]

Alpha,

I don't know it, however how would the expression know that it is a
concatination if you use a system.Int32 and a system.string.

If the problem is that your first operand is an integer, than you can maybe
try the trick to add in advance a '' + (double single quote) .

Just a try and a guess

Cor
 
G

Guest

Can I fill a dataset table with a SQL SERVER View? That way I can easily
concatenate an cast the int type to string and form a column that way. What
would the sytax be if I can fill with View? I only know so far to do SQL
select from table with Select command object.

Thanks, Alpha
 
G

Guest

I created a view in SQL SERVER and I fill the dataset by selecting the
concatenated column from the view and it works. Thanks, Alpha
 

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

Top