|
After the strings are retrieved, u need to format the strings accordingly.
Suppose if u get sEmpid from the corresponding control,
Then in order to convert it into int,
u need to do
CString sEmpid ;<br />
GetDlgItemText(IDC_EDIT1,sEmpid );<br />
int iEmpId;<br />
iEmpId= atoi(strTest.GetBuffer(strTest.GetLength()));
Appu..
"If you judge people, you have no time to love them."
-- modified at 2:01 Thursday 1st June, 2006
|
|
|
|
|
Or Use GetDlgItemInt to get the Int data from the control
Appu..
"If you judge people, you have no time to love them."
|
|
|
|
|
A couple of things I noticed.
1. Are all the fields in your table "text"? You are inserting values as if they are text, which probably will give you a type mismatch error (I'm not real familiar with MySql).
2. I don't think you need to escape the single quote characters (i.e. instead of \', can't you just use '?). Makes it hard for me to read.
What error are you getting exactly?
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
yogikaushik wrote: where i am wrong........
You're going to need to narrow the problem down to just a few lines of code. No one likes to wade through a bunch of irrelevant code. What is the problem you are seeing? Have you single-stepped through the code to find the offending statement(s)? Help us to help you.
"The largest fire starts but with the smallest spark." - David Crow
|
|
|
|
|
like:
switch (n) {
case 0:
int i=0; //<<<<<<<<<<<<<<<<<
break;
case 1:
break;
}
|
|
|
|
|
switch (n) {
case 0:
{
int i=0; //<<<<<<<<<<<<<<<<<
}
break;
case 1:
break;
}
This is how it is done in VC7
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
It is my understanding that you can only use the variable within the case block. When you exit out of the block, the variable goes out of scope and it is destroyed.
Steve
|
|
|
|
|
Yes this is very true . The scope of the variable is only in the case block.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
_AnShUmAn_ wrote:
This is how it is done in VC7
Nothing VC7-specific about it. This is how it has been done in C as far back as I can remember.
"The largest fire starts but with the smallest spark." - David Crow
|
|
|
|
|
how i link two MFC projects to visual C++ 6.0 ??
-- modified at 0:39 Thursday 1st June, 2006
|
|
|
|
|
U mean, inserting a project into another project.
Do this.
Right Click on the workspace,then click on Insert project in to workspace.
then u can observe both the project in the same workspace.
hope this helps.
Appu..
"If you judge people, you have no time to love them."
|
|
|
|
|
Hi,
I am working in vc++ for past 4 months.But i dont know very much about MFC.That is where the variables stored and memory allocation like that.When im doing coding,i got error as unhandled exception,Out of memory like that.So, i think im unaware about the memory allocation.So, Is there any tutorial about this allocation etc.,..?
|
|
|
|
|
|
Anu_Bala wrote: I am working in vc++ for past 4 months.But i dont know very much about MFC.That is where the variables stored and memory allocation like that.When im doing coding,i got error as unhandled exception,Out of memory like that.So, i think im unaware about the memory allocation.So, Is there any tutorial about this allocation etc.,..?
Well some of the things I know I would like to share.
- Use
new and delete .
- Always use
delete[] with new[] and delete with new - Do not mix up c, c++. Either you use C, or use C++ for memory allocation.
- Always set a pointer to
NULL after deletion.
- Always allocate sufficient amount of memory. Do not allocate memory like this...
char *str = new char[ strlen( someStr ) ];
strcpy( str, someStr );
delete [] str;
str = NULL;
instead use
char *str = new char[ strlen(someStr) + 1 ];
strcpy( str, someStr );
delete [] str;
str = NULL;
- Try using
auto_ptr ;
- Maintain a list of pointers to memory that you have allocated. When you exit from your app you can delete them all at one go if any of them hasn't been deleted.
- Always check for
NULL on pointers after a new .
- Always check for
NULL on pointers before using them.
- Be really really afraid to dynamically allocate memory.
Nibu thomas
A Developer
Programming tips[^] My site[^]
|
|
|
|
|
Nibu thomas wrote: strcpy( str, someStr );// well asking for trouble
True, use strncpy() instead.
Nibu thomas wrote: delete [] str;//error here
Why do you assert this is in error?
Nibu thomas wrote: Be really really afraid to dynamically allocate memory.
Why?
"The largest fire starts but with the smallest spark." - David Crow
|
|
|
|
|
DavidCrow wrote: Nibu thomas wrote:
delete [] str;//error here
That was in relation to the point I mentioned. i.e. to allocate sufficient amount of memory. Well if you are using strcpy for that purpose strcpy will put a NULL char just after the end of the memory block. And when you try to delete such pointers it will result in memory damaged error message.
strcpy was used here just to regenerate that issue.
DavidCrow wrote: Nibu thomas wrote:
Be really really afraid to dynamically allocate memory.
Why?
Yeah, use it as a last resort. For eg: using standard stl classes can avoid most of the issues.
Note: I didn't say not to use it but instead to be afraid. Sometimes being afraid is good.
Nibu thomas
A Developer
Programming tips[^] My site[^]
|
|
|
|
|
Nibu thomas wrote: Well if you are using strcpy for that purpose strcpy will put a NULL char just after the end of the memory block.
But the point is that the source could be longer than the destination, which is why strcpy() should not be used, regardless of how it deals with the \0 terminator.
Nibu thomas wrote: For eg: using standard stl classes can avoid most of the issues.
Last time I checked, STL used memory from the heap (i.e., dynamic). There's just not any way around not using memory from the heap.
"The largest fire starts but with the smallest spark." - David Crow
|
|
|
|
|
DavidCrow wrote: But the point is that the source could be longer than the destination, which is why strcpy() should not be used, regardless of how it deals with the \0 terminator.
Exactly, I was just demonstrating how such things could happen.
DavidCrow wrote: Last time I checked, STL used memory from the heap (i.e., dynamic). There's just not any way around not using memory from the heap.
Exactly, they work by allocating on the heap. But then we don't have to do it. These are proven classes (AFAIK) which work efficiently. Hence using them would be best for us. These classes takes the onus on them to do memory clean up.
Nibu thomas
A Developer
Programming tips[^] My site[^]
|
|
|
|
|
I suggest you to read Effective C++ 2nd Edition or the latest 3rd Edition.
If u r confused about pointers, read Pointers in C to know more about pointers.
as nibu said if u r much concerned about pointers, try using auto_pointers that is the best way to handle memory leaks. but I suggest that not to use auto_pointer because simply u can handle those allocation and deallocation of objects.
In MFC, it is not using any special allocation strategy, its all C++.
Code Complete 2 is a book which contains some best practices.
SaRath
"D on't blindly follow rules you read somewhere without verifying that it makes sense for your situation!"
|
|
|
|
|
SaRath C wrote: In MFC, it is not using any special allocation strategy, its all C++.
That is not entirely accurate.
See this MSDN Article[^]
"What classes are you using ? You shouldn't call stuff if you have no idea what it does" Christian Graus in the C# forum
led mike
|
|
|
|
|
Thanks for ur information. It was quite new for me.
Anu said that (he/she) is new to MFC and suffering with some exception and all.
Everything has an user point of view. We are the users of C++ right, at our point of view, operator new has a standard form and a predefined way which it should be used. I just indicated about that fact. never I meant any regarding internal handling of compiler. I think the language I used was something not proper
SaRath
"D on't blindly follow rules you read somewhere without verifying that it makes sense for your situation!"
-- modified at 1:55 Thursday 1st June, 2006
|
|
|
|
|
SaRath C wrote: at our point of view, operator new has a standard form and a predefined way which it should be used. I just indicated about that fact.
ah, I understand now, thanks.
-- signature under construction -- -pete
|
|
|
|
|
Need a way in C++ to determine how much memory a user has on their graphics card. Either DirectX or some other way. Any leads?
===================
Matthew R. Miller
www.bytemycode.com
www.codeandcoffee.com
|
|
|
|
|
Im not sure maybe it is some helpful to you Here[^]
whitesky
|
|
|
|
|
I just moved some code from a CWinThread into a new thread (standard thread) and am now getting stack overflows (while accessing a COM engine -- "DesktopSearch").
Any clues for me?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.soonr.com">SoonR Inc.</A>
|
|
|
|