I am developing a Windows Forms Application in C# with 2.0 being the underlying .Net Framework. I use .Net Framework Data Provider for ODBC in order to connect to a specific access database.
I have a field say "NumberColumn" with 'Number' datatype & another field say "StringColumn" with 'Text' datatype in one of the tables present in the database. I have to concatenate the values present in the two fields in this format ("StringColumn-NumberColumn").
I tried using the con开发者_开发技巧vert function "CStr" in the query to convert the number column and append with the string column but am getting an exception "Invalid scalar function CStr".
Presently, am doing this concatenation in the DataTable level which I feel is expensive considering the huge amount of data. How could I achieve the concatenation in the specified format while querying the data?
I don't think you mention the database but I would expect something like
select StringColumn || '-' || cast( NumberColumn as varchar ) from table
may do what you want, but that becomes database dependent.
If you are saying its access, and you are using the jet provider then I would think that
select StringColumn + '-' + {fn cstr( NumberColumn )} from table
Would work. At least it does directly to the MS Access ODBC driver
精彩评论