Newbie Variable question 
Author Message
 Newbie Variable question

Another basic question...

I pulled a count of records from a table like this:

 this->req_count = new SqlCommand(S"select count(*) from
table where column1 = 1 and column2 = 3",database);

this->readera = req_count->ExecuteReader();
int count;
while(readera->Read()){
   count = readera->GetInt32(0);

Quote:
}

This worked, but when I tried to display this count like
this:

Label->Text = count;

I received the int vs String error message.
I then tried:

String*  count;
while(readera->Read()){
   count = readera->GetInt32(0);

Quote:
}

which ofcourse failed and

String* count;
while(readera->Read()){
   count = readera->GetString(0);

Quote:
}

Which also failed.

then I tried _itoa derivatives and the ToString()function.

such as
String* count2;
int count;
while(readera->Read()){
   count = readera->GetString(0);

Quote:
}

count2->ToString(count,0);

Each failed to convert the data. I understand that when
you specify a String* that it contains (can contain)
formatting info not usually seen in a non String*
variable, but it would seem only logical that there be a
conversion function to accomplish this. I was able to get
this to work:

int row;
String* sel;
row = text1->CurrentRowIndex;
sel = text1->get_Item(row, 0)->ToString();

It is part of a context menu on a datagrid. Why does this
work and the other does not?  Can anyone assist me in
demystifying this? I am very confused.

Thanks.
Scott



Wed, 01 Dec 2004 02:40:53 GMT  
 Newbie Variable question
Hi Scott,

It looks like you need something like this instead:
Label->Text = __box(count)->ToString();

Silviu Guea
Visual C++ Compiler Team


Quote:
> Another basic question...

> I pulled a count of records from a table like this:

>  this->req_count = new SqlCommand(S"select count(*) from
> table where column1 = 1 and column2 = 3",database);

> this->readera = req_count->ExecuteReader();
> int count;
> while(readera->Read()){
>    count = readera->GetInt32(0);
> }

> This worked, but when I tried to display this count like
> this:

> Label->Text = count;

> I received the int vs String error message.
> I then tried:

> String*  count;
> while(readera->Read()){
>    count = readera->GetInt32(0);
> }
> which ofcourse failed and

> String* count;
> while(readera->Read()){
>    count = readera->GetString(0);
> }

> Which also failed.

> then I tried _itoa derivatives and the ToString()function.

> such as
> String* count2;
> int count;
> while(readera->Read()){
>    count = readera->GetString(0);
> }
> count2->ToString(count,0);

> Each failed to convert the data. I understand that when
> you specify a String* that it contains (can contain)
> formatting info not usually seen in a non String*
> variable, but it would seem only logical that there be a
> conversion function to accomplish this. I was able to get
> this to work:

> int row;
> String* sel;
> row = text1->CurrentRowIndex;
> sel = text1->get_Item(row, 0)->ToString();

> It is part of a context menu on a datagrid. Why does this
> work and the other does not?  Can anyone assist me in
> demystifying this? I am very confused.

> Thanks.
> Scott




Wed, 01 Dec 2004 10:39:32 GMT  
 Newbie Variable question
That's great!
Thanks.
Oh do you know where I can find information on that
function, and others like it? I am very new to vc++ and as
such I am having a hard time making the transition from
Perl style languages to vc++.

Thanks again.

C.S Schuler

Quote:
>-----Original Message-----
>Hi Scott,

>It looks like you need something like this instead:
>Label->Text = __box(count)->ToString();

>Silviu Guea
>Visual C++ Compiler Team



Fri, 03 Dec 2004 21:51:35 GMT  
 Newbie Variable question
MSDN is your friend. But if you're new to c++ some books will definitivelly
help.
Silviu


Quote:
> That's great!
> Thanks.
> Oh do you know where I can find information on that
> function, and others like it? I am very new to vc++ and as
> such I am having a hard time making the transition from
> Perl style languages to vc++.

> Thanks again.

> C.S Schuler

> >-----Original Message-----
> >Hi Scott,

> >It looks like you need something like this instead:
> >Label->Text = __box(count)->ToString();

> >Silviu Guea
> >Visual C++ Compiler Team



Wed, 08 Dec 2004 07:14:52 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Newbie C question regarding static & const variables

2. newbie question on evaluating a string variable

3. Global variables (newbie question)

4. Setting a method variable from within a switch statement - Newbie question

5. Random Variable help! (newbie question)

6. C newbie question about Variable number of arguments

7. Newbie Question: variable types

8. Global Variables in MFC - Newbie Question

9. Help! Newbie question on viewing variables in debugger

10. newbie: passing/returning variable to a dialog

11. NEWBIE: Initialization of member variables

12. Newbie: Howto convert char variable __gc into CString?

 

 
Powered by phpBB® Forum Software