|
Use
ShowWindow(SW_MAXIMIZE);
I hope it helps.
Regards,
Sandip.
|
|
|
|
|
I have used this code to delete files from the current directory. But it not works.
Actually i cant use the full path. As because i dont know where my software will install. It may be D:\\or else also
SHFILEOPSTRUCT sfo;
sfo.pTo = NULL;
sfo.hwnd = NULL;
sfo.wFunc = FO_DELETE;
sfo.pFrom = "..\\Test\\*.txt\0";
sfo.fFlags = FOF_FILESONLY | FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI;
SHFileOperation(&sfo);
modified on Thursday, October 23, 2008 2:55 AM
|
|
|
|
|
You better use a complete path like "C:\\...\\*.txt
Greetings from Germany
|
|
|
|
|
Actually i cant use the full path. As because i dont know where my software will install. It may be D:\\or else also
|
|
|
|
|
Dont write files in the installation directory. Vista will knock you out!!!
Use a user path:
-> SHGetFolderPath
-> GetCurrentDirectory
-> write some path information in the registry (in the setup)
Greetings from Germany
|
|
|
|
|
Sk Mohiuddin wrote: sfo.pFrom = "..\\Test\\*.txt\0";
Documentation says:
pFrom
A pointer to one or more source file names. These names should be fully-qualified paths to prevent unexpected results.
I hope it helps.
BTW: You can use GetModuleFileName[^] to get the path of your executable.
Regards,
Sandip.
|
|
|
|
|
SEE MY CODE BELOW:
Ive got a dialog box where i enter Contact Details......
Ive To Insert IT Into Access Database........
//Take the values entered in edit box to CEdit *
m_First.GetWindowText(Firstname);
m_Last.GetWindowText(Lastname);
m_Add.GetWindowText(Address);
CString FullName = "INSERT INTO Contacts (FirstName, LastName, Address) VALUES ('" +Firstname+ "', '" +Lastname+"','" + Address+"'))";
executeSQL((SQLCHAR *) FullName);
ERROR :
CANNOT CONVERT CString to SQLCHAR*
|
|
|
|
|
anna mathew wrote: CANNOT CONVERT CString to SQLCHAR*
What the hell is an SQLCHAR* anyways?
anna mathew wrote: executeSQL((SQLCHAR *) FullName);
Why can't you just do it with the CString variable itself?
ExecuteSQL(FullName);
Why the wrong spelling (executeSQL instead of ExecuteSQL)? Is that a separate function you wrote?
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Rajesh R Subramanian wrote: What the hell is an SQLCHAR* anyways?
Is is a ODBC API's data type:
typedef unsigned char SQLCHAR;
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Looks like MSDN doesn't know it but...
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Sure [^]?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Touché!
I just did a search on MSDN, but the results were of no avail to reveal this secret datatype.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
thank you....
i tried it..but a new error comes up
error C2594: 'static_cast' : ambiguous conversions from 'void (__thiscall CInsert::* )(void)' to 'AFX_PMSG'
|
|
|
|
|
anna mathew wrote: i tried it..but a new error comes up
You tried what? Why don't you just show the code and be precise in asking questions? Do we need to ask you 10 questions just to get to know your exact problem?
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Rajesh R Subramanian wrote: You tried what? Why don't you just show the code and be precise in asking questions? Do we need to ask you 10 questions just to get to know your exact problem?
Ya sir, but plz plz help, u r aware: your signature says it all
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I haven't understood yet if you're calling a CDatabase method or not, because I cannot find a ExecuteSQL function in ODBC API .
If you're using MFC to do database access then you don't need SQLCHAR data type.
Could you please post a more complete code snippet (don't forget to format it using 'code block' button)?
Could you you please explain better the scenario and your requirements?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
look what a SQLCHAR* is i guess SQLCHAR[] make one and copy the CString to it.
Greetings from Germany
|
|
|
|
|
Why do you need SQLCHAR ? Aren't you using CDatabase ?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
modified on Thursday, October 23, 2008 3:55 AM
|
|
|
|
|
now im using CDatabase....
and modified code to :
void CInsert::OnBnClickedOk()
{
OnOK();
SQLRETURN sr;
SQLHSTMT hstmt;
//SQLCHAR SQL[] ="INSERT INTO Contacts (FirstName, LastName, Address) VALUES('?','?','?')";
//Take the values entered in edit box to CEdit *
m_First.GetWindowText(Firstname);
m_Last.GetWindowText(Lastname);
m_Add.GetWindowText(Address);
CString Full ="INSERT INTO Contacts (FirstName, LastName, Address) VALUES ('" +Firstname+ "', '" +Lastname+"','" + Address+"'))"; SQLINTEGER FirstNameLength = SQL_NTS;
sr = ExecuteSQL(Full);
if(sr != SQL_SUCCESS && sr != SQL_SUCCESS_WITH_INFO)
displayODBCError(sr,"Error in ExecuteSQL");
SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
}
................
still now same error.........
error C2594: 'static_cast' : ambiguous conversions from 'void (__thiscall CInsert::* )(void)' to 'AFX_PMSG'
|
|
|
|
|
Ive Edited My Code To:
void CInsert::OnBnClickedOk()
{
OnOK();
SQLRETURN sr;
SQLHSTMT hstmt;
SQLCHAR SQL[] ="INSERT INTO Contacts (FirstName, LastName, Address) VALUES('?','?','?')";
//Take the values entered in edit box to CEdit *
m_First.GetWindowText(Firstname);
m_Last.GetWindowText(Lastname);
m_Add.GetWindowText(Address);
SQLINTEGER FirstNameLength = SQL_NTS;
SQLINTEGER AddressLength = SQL_NTS;
SQLINTEGER LastNameLength = SQL_NTS;
SQLINTEGER FullLength = SQL_NTS;
// Allocate a new statement handle
sr = SQLAllocHandle(SQL_HANDLE_STMT, hDbConn, &hstmt);
// Prepare statement
if(sr != SQL_SUCCESS && sr != SQL_SUCCESS_WITH_INFO)
displayODBCError(sr,"Error in SQLAllocHandle in OnViewTestpreparedinsert");
sr = SQLPrepare(hstmt, SQL, SQL_NTS);
if(sr != SQL_SUCCESS && sr != SQL_SUCCESS_WITH_INFO)
displayODBCError(sr,"Error in SQLPrepare in OnViewTestpreparedinsert");
// Bind Parameters
sr = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 10, 0,
&Firstname, sizeof(Firstname), &FirstNameLength);
if(sr != SQL_SUCCESS && sr != SQL_SUCCESS_WITH_INFO)
displayODBCError(sr,"Error in Binding 2 in OnViewTestpreparedinsert");
sr = SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT,
SQL_C_CHAR, SQL_CHAR, 10, 0, &Lastname, sizeof(Lastname), &LastNameLength);
if(sr != SQL_SUCCESS && sr != SQL_SUCCESS_WITH_INFO)
displayODBCError(sr,"Error in Binding 3 in OnViewTestpreparedinsert");
sr = SQLBindParameter(hstmt, 3, SQL_PARAM_INPUT,SQL_C_CHAR, SQL_CHAR, 10, 0,
&Address, sizeof(Address), &AddressLength);
if(sr != SQL_SUCCESS && sr != SQL_SUCCESS_WITH_INFO)
displayODBCError(sr,"Error in Binding 3 in OnViewTestpreparedinsert");
// Execute statement with parameters
sr = SQLExecute(hstmt);
if(sr != SQL_SUCCESS && sr != SQL_SUCCESS_WITH_INFO)
displayODBCError(sr,"Error in SQLExecute in OnViewTestpreparedinsert");
SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
}
...................................................................
Ive Also Tried ...........
void CInsert::OnBnClickedOk()
{
// TODO: Add your control notification handler code here
OnOK();
SQLRETURN sr;
//Take the values entered in edit box to CEdit
m_First.GetWindowText(Firstname);
m_Last.GetWindowText(Lastname);
m_Add.GetWindowText(Address);
CString FullName = "INSERT INTO Contacts (FirstName, LastName, Address) VALUES ('" +Firstname+ "', '" +Lastname+"','" + Address+"'))";
executeSQL((SQLCHAR *) (LPCTSTR)FullName);
}
................................
Both I get the Same ERROR::::::
error C2594: 'static_cast' : ambiguous conversions from
'void (__thiscall CInsert::* )(void)' to 'AFX_PMSG'
........................Y Is It?
|
|
|
|
|
anna mathew wrote: sr = SQLExecute(hstmt);
Doesn't it work? What error do you get?
anna mathew wrote: executeSQL((SQLCHAR *) (LPCTSTR)FullName);
My previous suggestion was a crap, please ignore it (I've deleted)
I don't know any executeSQL function. From where have you got it?
BTW please answer to our questions to help us to help you
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Ive Reffered InformIT C++ 6 Unleashed to do database programming......
Ive not used CDatabase......
In My Program ...Initially Thr Is A Menu Bar With Options...
Connect...Insert....Delete...and View...
on Clicking Connect I get Connected to Database...
all the other options can be pressed only after this...
initially my code was working.....
in Insert,Delete functions i had given only one statement...
that is :
executeSQL((SQLCHAR *) "INSERT INTO Contacts (Firstname,Lastname,Address) values ('MIKE', 'C', 'India'");
//in delete
executeSQL((SQLCHAR *) "DELETE FROM Contacts WHERE FirstName ='MIKE'");
//code executeSQL
void CMsQueryView::executeSQL (SQLCHAR *SQL)
{
SQLRETURN sr; //Return code for your ODBC calls
SQLHSTMT hstmt;
// Allocate new Statement Handle based on previous connection
sr = SQLAllocHandle(SQL_HANDLE_STMT, hDbConn, &hstmt);
if(sr != SQL_SUCCESS && sr != SQL_SUCCESS_WITH_INFO)
{
char message[200];
sprintf (message, "Error Allocating Handle: %d\n", sr);
AfxMessageBox(message);
}
sr = SQLExecDirect(hstmt, SQL, SQL_NTS);
if(sr != SQL_SUCCESS && sr != SQL_SUCCESS_WITH_INFO)
{
char message[200];
sprintf (message, "Error in SQLExecDirect. SQL was:\n\n%s\n\n", SQL);
displayODBCError(sr, message);
}
SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
}
//odbc error function
void CMsQueryView::displayODBCError (SQLRETURN sr,char *inMessage)
{
if(sr != SQL_SUCCESS && sr != SQL_SUCCESS_WITH_INFO)
{
SQLCHAR SqlState[6];
SQLINTEGER NativeError;
SQLCHAR ErrMsg[SQL_MAX_MESSAGE_LENGTH];
int i = 1;
char message[512];
strcpy (message, "");
if (inMessage)
{
strcpy(message, inMessage);
strcat(message, " — ");
}
sprintf(message, "%sError in SQLConnect(): %d.",
message, sr);
AfxMessageBox(message);
while(SQLGetDiagRec(SQL_HANDLE_DBC, hDbConn, i,SqlState, &NativeError,
ErrMsg, sizeof(ErrMsg), NULL)!= SQL_NO_DATA)
{
sprintf(message,"Diag: %d, SQLSTATE: %s NativeError: %d ErrMsg: %s",
i++, SqlState, NativeError, ErrMsg);
AfxMessageBox(message);
}
}
}
........................................
then it worked.....
now im tryin to get the values from user and then tryin to write it to database.....
thats y i made the changes to BnClickedOk()
|
|
|
|
|
I dint know database programming in MFC....
So I reffered the book and followedthe code...
if there is much easier way of Doing It Then DO SUGGEST...
Im Using ODBC and ACCESS database
|
|
|
|
|
Wow, finally some light in the darkness!
If you are building a UNICODE application (Visula Studio 2003 and above default) then the CString object represent wide characters string, while SQLCHAR * is still a ANSI (C-like) string. you may use the macro CT2A for the required conversion (you have to include atlconv.h in you source file), for instance:
#include <atlconv.h>
CT2A sqlFullName(FullName);
executeSQL((SQLCHAR *) (LPSTR) sqlFullName);
[added]
you may also avoid string conversions using CStringA class, for instance:
CStringA szQuery = "SELECT * FROM MYTABLE";
executeSQL((SQLCHAR *) (LPCSTR) szQuery);
[/added]
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
|