473,386 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to convert an integer to a string

I am having a problem with a relatively simple sql query, and was
hoping that somebody could help me on this forum.

Basicaly the situation is that I have two tables, a Vendors table
(Vendors) and a ProductCatalogue table (ProdCat).

I wish to select the VendorID, and VendorName from the vendors table.
Additionally I want to run a subquery on (SELECT COUNT(*) FROM ProdCat
WHERE ProdCat.Pcat_VendID=Vendors.Vend_ID). I want to concatenate the
result of the subquery with the VendorName colunm.

I created the following statement:
SELECT Vend_ID, Vend_Name + '(' + (SELECT COUNT(*) FROM ProdCat WHERE
ProdCat.Pcat_VendID=Vendors.Vend_ID)'+ products) AS display FROM
Vendors;

When I run this query I get the following message:
The provider could not determine the Double value. For example, the row
was just created, the default for the Double column was not available,
and the consumer had not yet set a new Double value.

I believe the problem occurs during concatenation, since the Vend_Name
colunm is a string while the subquery result is an integer. I have
tried using the convert function. Unfortunaly it seems that MS Access
does not support this function as I got a (Undefined function 'convert'
in expression.) error message.

I was wondering if anybody knows a way around this problem. I could get
the subquery result in a separate column and then later concatenate it
with the Vend_Name column programmatically, but I think it would be
neater to do it in the sql query.

Nov 13 '05 #1
9 73807
"photomonkey" <pa**********@gmail.com> wrote in
news:11**********************@g44g2000cwa.googlegr oups.com:
I am having a problem with a relatively simple sql query, and
was hoping that somebody could help me on this forum.

I believe the problem occurs during concatenation, since the
Vend_Name colunm is a string while the subquery result is an
integer. I have tried using the convert function. Unfortunaly
it seems that MS Access does not support this function as I
got a (Undefined function 'convert' in expression.) error
message.


The Access help will tell you that to convert a number to a string,
use the Cstr() function.

However, you may want to use the Format() function, to add leading
zeroes, etc. It's described in the help too.

--
Bob Quintal

PA is y I've altered my email address.
Nov 13 '05 #2
Thanks Bob quintal, you replied really quickly.

I forgot to mention that I am not using VB. I am programming a page in
ASP.NET and C#. What I was wanting to do was to populate a dropdownlist
with the query result more or less on the following way:

OleDbDataReader dr = command.ExecuteReader();
this.ddlVendID.DataSource = dr;
this.ddlVendID.DataTextField = "display";
this.ddlVendID.DataValueField = "Vend_ID";
this.ddlVendID.DataBind();

Do you have any suggestions for what I might do to only get two columns
back after calling OleDbCommand.ExecuteReader() ?

I guess "ToString()" is the C# equivalent for "Cstr()", but how could
I make use of this and bind the DataReader object directly to the
dropdownlist?

Thanks for your help, I have been spending several hours trying to a
neat way of doing this but have yet not found one.

Nov 13 '05 #3
"photomonkey" <pa**********@gmail.com> wrote in
news:11**********************@g47g2000cwa.googlegr oups.com:
I forgot to mention that I am not using VB.


Then why are you posting in an Access newsgroup? Ypu aren't using
Access, though you may have used Access to create the MDB file
you're storing your data in.

You're communicating with the Jet database engine, yes, but Jet is
an entity entirely separate from Access (it ships on every Windows
PC, as it is used for storing Active Directory data, which should
indicate to you that it's not obsolete, nor untrustworthy).

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #4
Given that this newsgroup is devoted to Microsoft Access database software,
I'd think you would have a far better chance of getting good information
about .NET's builtin functions in a .NET newsgroup. There are quite a
number, both in USENET and Microsoft's sponsored newsgroups at the free
newsserver news.microsoft.com.

Because of the subject of this newsgroup, unless told otherwise, we just
naturally assume a question is about Access and the VBA used by Access. It
is a waste of both the asker and answerer's time to ask C# or VB.NET-
specific questions here, without saying that is what you are asking about.

Larry Linson
Microsoft Access MVP

"photomonkey" <pa**********@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Thanks Bob quintal, you replied really quickly.

I forgot to mention that I am not using VB. I am programming a page in
ASP.NET and C#. What I was wanting to do was to populate a dropdownlist
with the query result more or less on the following way:

OleDbDataReader dr = command.ExecuteReader();
this.ddlVendID.DataSource = dr;
this.ddlVendID.DataTextField = "display";
this.ddlVendID.DataValueField = "Vend_ID";
this.ddlVendID.DataBind();

Do you have any suggestions for what I might do to only get two columns
back after calling OleDbCommand.ExecuteReader() ?

I guess "ToString()" is the C# equivalent for "Cstr()", but how could
I make use of this and bind the DataReader object directly to the
dropdownlist?

Thanks for your help, I have been spending several hours trying to a
neat way of doing this but have yet not found one.

Nov 13 '05 #5
On 15 Aug 2005 15:06:27 -0700, "photomonkey" <pa**********@gmail.com>
wrote:

The *Double* value? That is completely illogical. You did not have a
Double field in this query, did you?

-Tom.

I am having a problem with a relatively simple sql query, and was
hoping that somebody could help me on this forum.

Basicaly the situation is that I have two tables, a Vendors table
(Vendors) and a ProductCatalogue table (ProdCat).

I wish to select the VendorID, and VendorName from the vendors table.
Additionally I want to run a subquery on (SELECT COUNT(*) FROM ProdCat
WHERE ProdCat.Pcat_VendID=Vendors.Vend_ID). I want to concatenate the
result of the subquery with the VendorName colunm.

I created the following statement:
SELECT Vend_ID, Vend_Name + '(' + (SELECT COUNT(*) FROM ProdCat WHERE
ProdCat.Pcat_VendID=Vendors.Vend_ID)'+ products) AS display FROM
Vendors;

When I run this query I get the following message:
The provider could not determine the Double value. For example, the row
was just created, the default for the Double column was not available,
and the consumer had not yet set a new Double value.

I believe the problem occurs during concatenation, since the Vend_Name
colunm is a string while the subquery result is an integer. I have
tried using the convert function. Unfortunaly it seems that MS Access
does not support this function as I got a (Undefined function 'convert'
in expression.) error message.

I was wondering if anybody knows a way around this problem. I could get
the subquery result in a separate column and then later concatenate it
with the Vend_Name column programmatically, but I think it would be
neater to do it in the sql query.


Nov 13 '05 #6
Sorry if I posted in the wrong group.

I won't say that I am a very experienced programmer. I am just trying
to get some university work done. I thought the problem was due to the
way Access implements SQL. SQL has a function "Convert" that converts a
number (double) to a string. However, it seems that this function is
not supported by Access. I tried searching the web for the equivalent
of function, but did not get any relevant results.

I was hoping somebody would be able to tell me if there is a way of
converting a double to a string while the query is being executed.
This is why, I thought that the programming languague I use would be
irrelevant, and that I only needed to bother about calling a native MS
Access function.

Nov 13 '05 #7
I think I get a *Double* as the subquery result (SELECT COUNT(*) FROM
ProdCat WHERE ProdCat.Pcat_VendID=Vendors.Vend_ID).

If I substitute this subquery with the column name of another
text-based, the sql statement executes without problems. It also
concatenates in the way intended.

This is the reason why I think it is necessary to convert the subquery
result to a string. but c# code does not work on the sql statement, and
I thought it would be likely that access has some function for this. I
have not been able to find this function on the access help file either.

Nov 13 '05 #8
"photomonkey" wrote
This is why, I thought that the program-
ming languague I use would be irrelevant,
and that I only needed to bother about
calling a native MS Access function.


David's response gives the reason, though it may not be obvious. You are
using the Jet database engine to commuincate with a Jet database. It happens
that the Jet database engine is the default DB engine installed by Access
and even Microsoft is not careful to be precise in their terminology.

You _were_ calling a native Access function, but Access is nowhere involved
in your database Access, and Jet has no comparable native SQL function.
<SIGH>

If you were running that Query from Access, it would likely work
just-fine-thankee.

Larry Linson
Microsoft Access MVP
Nov 13 '05 #9
OK, I get it now.

I was not aware that Access and Jet were two different things. I guess
I learned something new today. Anyway, thanks a lot for the help.

Nov 13 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Hector A | last post by:
Hi I'm trying to convert a string that already looks like a date to a date that I can use when I pass it from java to the database. I receive the date in format yyyy-mm-dd and I need it to be a...
5
by: KB | last post by:
Hi, This may be a rudimentary question: How to convert a string like '777' to an octal integer like 0777, so that it can be used in os.chmod('myfile',0777)? I know the leading zero is...
2
by: lizayica | last post by:
How to convert a string like '2,3,4' to three integer 2,3,4 in SQL procedure of DB2 UDB 8.2? Thanks!
3
by: Convert TextBox.Text to Int32 Problem | last post by:
Need a little help here. I saw some related posts, so here goes... I have some textboxes which are designed for the user to enter a integer value. In "old school C" we just used the atoi function...
7
by: henrytcy | last post by:
Hi, How can I convert integer, for example 12113, to char array but without specify an array size in C programming? Thanks!
13
by: coinjo | last post by:
Is there any function to determine the length of an integer string?
3
by: priyanka | last post by:
Hi there, I want to convert a String into integer. I get the string from a file using : string argNum; getline(inputStream,argNum); I now need to convert argNum into integer.
3
by: palani12kumar | last post by:
hi. I want to get a string as input. If the input is an integer i want to save it to an int variable. I know to convert a number to int. but how to convert a string to number(integer). in C++
9
by: vaskar | last post by:
I have got one problem in VB.NET 2005 using unicode I want to add two numbers in vb.net 2005 through UNICODE I didn't know how to convert UNICODE string to integer. I hope you can solve my...
4
by: mthread | last post by:
Hi, I would like to know the method to convert integer to string. Thanx in advance.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.