开发者

How to convert Number Datatype to Text Datatype - ODBC Query - C#

开发者 https://www.devze.com 2023-03-14 13:23 出处:网络
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 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

0

精彩评论

暂无评论...
验证码 换一张
取 消