How to convert char* to char
-
Hi, Can u plz say how to convert char* variable to char. I write the code as shown below struct row{ char name[50]; char sex[5]; }; I am getting text from the edit box and assigning to row.name, I want to insert row.name into the database. char *CampID=new char[50]; GetDlgItemText (IDC_EDITCAMPAIGNID,CampID,50); row.name=CampID; But I am getting error saying that "Can not convert from char* to char[50]" Thanks in advance.
-
Hi, Can u plz say how to convert char* variable to char. I write the code as shown below struct row{ char name[50]; char sex[5]; }; I am getting text from the edit box and assigning to row.name, I want to insert row.name into the database. char *CampID=new char[50]; GetDlgItemText (IDC_EDITCAMPAIGNID,CampID,50); row.name=CampID; But I am getting error saying that "Can not convert from char* to char[50]" Thanks in advance.
tejaswini.g wrote:
char *CampID=new char[50]; GetDlgItemText (IDC_EDITCAMPAIGNID,CampID,50); row.name=CampID;
you need to use
strcpy
here.strcpy(row.name,CampID);
Prasad Notifier using ATL | Operator new[],delete[][^]
-
tejaswini.g wrote:
char *CampID=new char[50]; GetDlgItemText (IDC_EDITCAMPAIGNID,CampID,50); row.name=CampID;
you need to use
strcpy
here.strcpy(row.name,CampID);
Prasad Notifier using ATL | Operator new[],delete[][^]
Thank you. Shall I ask you One more doubt. I have created a propertysheet with two property pages. In the first property page i displayed 'employee names ' from the database and displayed in the grid lines. I select on name and activate another property page.Using querysiblings i got the name in the second property page. And using that ,employeename' i write a query to get the data from the database and displayed in the controls. First time it is running fine. Second time if i select another emplyoee name I am getting the correct results from database but the old data is displayed in the controls. Can u plz say How can I solve this problem? Thanks in advance.
-
Hi, Can u plz say how to convert char* variable to char. I write the code as shown below struct row{ char name[50]; char sex[5]; }; I am getting text from the edit box and assigning to row.name, I want to insert row.name into the database. char *CampID=new char[50]; GetDlgItemText (IDC_EDITCAMPAIGNID,CampID,50); row.name=CampID; But I am getting error saying that "Can not convert from char* to char[50]" Thanks in advance.
tejaswini.g wrote:
saying that "Can not convert from char* to char[50]"
You can also go around with this using CString if you are using MFC Define the structure as: struct row{ CString name; CString sex; }; // In your code where you are retrieving the string you can write: char *CampID=new char[50]; GetDlgItemText (IDC_MYEDIT,CampID,50); row r; r.name =(CString )CampID; AfxMessageBox (r.name); // r.name has same string as CampID
Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_
-
Thank you. Shall I ask you One more doubt. I have created a propertysheet with two property pages. In the first property page i displayed 'employee names ' from the database and displayed in the grid lines. I select on name and activate another property page.Using querysiblings i got the name in the second property page. And using that ,employeename' i write a query to get the data from the database and displayed in the controls. First time it is running fine. Second time if i select another emplyoee name I am getting the correct results from database but the old data is displayed in the controls. Can u plz say How can I solve this problem? Thanks in advance.
can you show some code?
Prasad Notifier using ATL | Operator new[],delete[][^]
-
can you show some code?
Prasad Notifier using ATL | Operator new[],delete[][^]
BOOL CCampaignDataEntryDlg::OnInitDialog() { CPropertyPage::OnInitDialog(); setUpODBC();// establish database connection long x=QuerySiblings(1,(long)&m_querySibling); CString* pString=(CString*)x; pStr=*pString; AfxMessageBox(pStr); //display employee name say 'tejaswini' SQLRETURN sr; SQLHSTMT hstmt; CString campid; campid.Format("SELECT empName,empID FROM EMPLOYEEDETAILS WHERE EMPNAME= '%s'",pStr); SQLCHAR* SQL = (SQLCHAR*)(LPCSTR)campid; } BOOL CCampaignDataEntryDlg::OnSetActive() { if(m_Status!="") //m_Status is to used to know whether the //property page is activated or not OnInitDialog(); return CPropertyPage::OnSetActive(); } BOOL CCampaignDataEntryDlg::OnKillActive() { m_Status="abc"; return CPropertyPage::OnKillActive(); }
-
BOOL CCampaignDataEntryDlg::OnInitDialog() { CPropertyPage::OnInitDialog(); setUpODBC();// establish database connection long x=QuerySiblings(1,(long)&m_querySibling); CString* pString=(CString*)x; pStr=*pString; AfxMessageBox(pStr); //display employee name say 'tejaswini' SQLRETURN sr; SQLHSTMT hstmt; CString campid; campid.Format("SELECT empName,empID FROM EMPLOYEEDETAILS WHERE EMPNAME= '%s'",pStr); SQLCHAR* SQL = (SQLCHAR*)(LPCSTR)campid; } BOOL CCampaignDataEntryDlg::OnSetActive() { if(m_Status!="") //m_Status is to used to know whether the //property page is activated or not OnInitDialog(); return CPropertyPage::OnSetActive(); } BOOL CCampaignDataEntryDlg::OnKillActive() { m_Status="abc"; return CPropertyPage::OnKillActive(); }
tejaswini.g wrote:
BOOL CCampaignDataEntryDlg::OnSetActive() { if(m_Status!="") //m_Status is to used to know whether the //property page is activated or not OnInitDialog(); return CPropertyPage::OnSetActive(); }
dont call
OnInitDialog
here. Instead write that code inOnSetActive
.Prasad Notifier using ATL | Operator new[],delete[][^]
-
tejaswini.g wrote:
char *CampID=new char[50]; GetDlgItemText (IDC_EDITCAMPAIGNID,CampID,50); row.name=CampID;
you need to use
strcpy
here.strcpy(row.name,CampID);
Prasad Notifier using ATL | Operator new[],delete[][^]
-
tejaswini.g wrote:
BOOL CCampaignDataEntryDlg::OnSetActive() { if(m_Status!="") //m_Status is to used to know whether the //property page is activated or not OnInitDialog(); return CPropertyPage::OnSetActive(); }
dont call
OnInitDialog
here. Instead write that code inOnSetActive
.Prasad Notifier using ATL | Operator new[],delete[][^]
Thank you.
-
BOOL CCampaignDataEntryDlg::OnInitDialog() { CPropertyPage::OnInitDialog(); setUpODBC();// establish database connection long x=QuerySiblings(1,(long)&m_querySibling); CString* pString=(CString*)x; pStr=*pString; AfxMessageBox(pStr); //display employee name say 'tejaswini' SQLRETURN sr; SQLHSTMT hstmt; CString campid; campid.Format("SELECT empName,empID FROM EMPLOYEEDETAILS WHERE EMPNAME= '%s'",pStr); SQLCHAR* SQL = (SQLCHAR*)(LPCSTR)campid; } BOOL CCampaignDataEntryDlg::OnSetActive() { if(m_Status!="") //m_Status is to used to know whether the //property page is activated or not OnInitDialog(); return CPropertyPage::OnSetActive(); } BOOL CCampaignDataEntryDlg::OnKillActive() { m_Status="abc"; return CPropertyPage::OnKillActive(); }
tejaswini.g wrote:
long x=QuerySiblings(1,(long)&m_querySibling); CString* pString=(CString*)x; pStr=*pString;
QuerySiblings()
does not return a value that can be cast to aCString
. If page two wants to know the name that was selected on page one, store that name in the sheet (the common link between pages).
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb