|
Anything you type into a text box is a string, whether letters, numbers or special characters. If you want to use numeric text as integer values then you need to convert them with one of the conversion methods. See Data Conversion | Microsoft Docs[^].
|
|
|
|
|
Thank you for the information .
|
|
|
|
|
Hello,
I created an MFC dialog application which is connected to MySql database. I wanted to create a search button/Search query for database.
Could you give me some pointers for creating functions for the same which accept string as well as Integers. Thanks.
I've read about atoi(), but still having problem.
And for displaying the search result, which one is better to use listbox or listcontrol.
|
|
|
|
|
If you have more than one column data to display, I would use CListCtrl[^] or CMFCListCtrl[^]
If you want to use an edit to use it for SQL statement, then give more details about what you intend to do there (e.g. sold > 1000 ?)
|
|
|
|
|
SQl is not greater than 1000. I wanted to create a simple application first. Like for example.. I have a table with ID(primary Key), Name, DOB...etc columns.
What I wanted to create is a search box in the dialog application. when I type the Name in the search box it will display the result in the listbox/list control box. Similarly when I enter the ID in the search box it will return the same.
|
|
|
|
|
You can use CListCtrl or derivated to display db data.
In search box you can test the user input with is_digit[^] and act accordingly (if is number then use ID to get data, or if is not number, use string to get the name and so on.
|
|
|
|
|
Thank you for always helping. I really appreciate the help
I have created a search function and now it's displaying in the CListCtrl and working the way I wanted.
I'll try to extend the functionality like if I select the result in the CListCtrl it will take me to another dialog that contains the details of the selected. If I have any doubt i'll post it here.
Thanks again 
|
|
|
|
|
You are welcome 
|
|
|
|
|
Hello I'm back again
How to get all the data present in a row displayed in the ListCtrl from the database and display those data in the next dialog?
For example:- There are name, age,dob..etc in a row.. when I select this row and press the select button.. It will take me to another where all this details will be display.
If you don't mind could you please give example.
Thanks.
|
|
|
|
|
Then you take all your list control data with CListCtrl::GetItemText[^] and you simply put them into next dialog, just like that:
CNextDlg dlg;
dlg.m_sName = m_ListCtrl.GetItemText(...);
dlg.m_sAge = m_ListCtrl.GetItemText(...);
dlg.m_sDOB = m_ListCtrl.GetItemText(...);
dlg.DoModal();
|
|
|
|
|
Thank you.
void CMyDlg::ResetListControl() {
m_ListControl.DeleteAllItems();
int iNbrOfColumns;
CHeaderCtrl* pHeader = (CHeaderCtrl*)m_ListControl.GetDlgItem(0);
if (pHeader) {
iNbrOfColumns = pHeader->GetItemCount();
}
for (int i = iNbrOfColumns; i >= 0; i--) {
m_ListControl.DeleteColumn(i);
}
}
I particularly don't understand this line :
CHeaderCtrl* pHeader = (CHeaderCtrl*)m_ListControl.GetDlgItem(0);
Could you please explain this line of code. Thanks 
|
|
|
|
|
I think that line should be:
CHeaderCtrl* pHeader = m_ListControl.GetHeaderCtrl();
See here[^].
However, that line retrieve first control item from m_ListCtrl object ... does working that line ? I didn't met such approach ...
|
|
|
|
|
Confidence that I have solved all strange errors here, I come back with some issue generated by a legacy C code for linux, code that I intend to use it in a MFC app in windows OS.
Ok. I have a simple code:
int nRespond = _open(device, 020);
UINT err = ::GetLastError();
where devide is const char* and has value C (or D:, or E: )
The nRespond is -1 and err has value 5, which is mean Access is denied . What could be the problem here ? I ran the test app as administrator mode (ran from VS2017 as admin mode).
|
|
|
|
|
The problem appears to be that you are expecting Linux code to work on Windows. The _open function opens a file - on unix systems you can open directories and devices as files, but not on Windows.
If you're lucky the code is actually expecting a normal file and you just passed in a device letter by mistake. Otherwise you will have to port the code, replacing the Linux system functions with code that does the same thing on Windows.
|
|
|
|
|
|
So I cannot open disk with this function ? ... this is the original code ... strange ...
|
|
|
|
|
_Flaviu wrote: this is the original code From where?
|
|
|
|
|
I get this code from a plain C code which has built for Linux:
int nRespond = _open(device, 020);
|
|
|
|
|
You cannot run Linux code on Windows without adjusting it for the differences. Windows does not let you address raw devices in the same way that Linux does. And in fact doing so is very dangerous as you could destroy your entire system.
|
|
|
|
|
And is any other method to open a device rather than _open in Windows ? I think I have to made some changes into Linux code to run on Windows ...
modified 4-Sep-19 7:31am.
|
|
|
|
|
I gave you a link in my first message above which shows details of how to address devices in Windows. However, the real question is, what exactly are you trying to do?
|
|
|
|
|
Your flags (020) are linux flags not windows try ( _O_WRONLY | _O_CREAT ) or some normal windows flags
_open, _wopen | Microsoft Docs[^]
I would add even in linux the code really should be written as flags not a value like that for this exact reason.
In vino veritas
modified 2-Sep-19 4:33am.
|
|
|
|
|
I have tried this:
int nRespond = _open(device, _O_WRONLY | _O_CREAT);
UINT e = ::GetLastError();
with the same result (error 5). Strange ....
|
|
|
|
|
I also tried this:
#include <io.h>
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
_open("D:", 0x02 | 0x04);
UINT e = ::GetLastError();
cout << e;
}
from cmd line as administrator rights … the same result: 5 (access is denied).
|
|
|
|
|
Big Errors
You can't open "D:" that isn't a file ... its not linux you don't mount drives
Try
int nRespond = _open("D:\\somefilename.txt", _O_WRONLY | _O_CREAT);
UINT e = ::GetLastError();
I am sure it will open
In vino veritas
|
|
|
|