|
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]
|
|
|
|
|
|
You are welcome.
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]
|
|
|
|
|
Hi All
can i write code on Picture click event?If yes then plz give me tips how can i rite?
Plz help me
Thanks in Advance
|
|
|
|
|
This is my first post here, or on any coding forum in fact. Before now I've always eventually been able to solve/explain/get around problems after some amount of banging my head against the wall. This though has me stumped, so if anyone can tell me what might be happening here I would be incredibly grateful since my project is stuck until I solve this, and I've pretty much given up.
I'll put the fundamental problem/question first since the rest of the information may be irrelevant. Basically, at a certain point in the execution of my code, the Win32 API call SendMessage() is returning 0, with GetLastError() also returning 0, yet the message is not being passed to the target window's WindowProc. I've tested by putting a breakpoint in the WindowProc (it't the right one, and execution is passing through there before and after this particular point, for the exact same window). I've also confirmed using Spy++, which again does not detect the sent message. I originally found the problem because WM_SIZE was not being received after calling SetWindowPos() with a new size, and through testing with Spy++ I found that WM_WINDOWPOSCHANGING(ED)/WM_NCCALCSIZE etc were being generated, but not WM_SIZE, despite the fact that the window size HAD changed. I temporarily got around it by simply doing my processing in response to WM_WINDOWPOSCHANGED instead of WM_SIZE, but then the problem appeared again when I send a user defined message to the window to ask it for it's requested size. The bottom line is that at this point in execution, SendMessage() is apparently doing nothing, even if I just try to send a WM_NULL message, it isn't delivered, Spy++ doesn't detect it even when the hook scope is all windows of the process. Does anyone know of any situation that can cause SendMessage() to silently fail to deliver its message to the destination window procedure?
A bit more info. I'm using native C++ and WTL, but the problem is related to the calls to the Win32 API, the WTL/ATL code is not relevant I'm pretty sure. I have some custom written window classes (derived from ATL::CWindowImpl) for my GUI, which act as containers and handle automatic positioning/resizing of their children when they are resized themselves, and send a message to their parent whenever they require resizing. In a certain case in my program I have a number of such windows nested within each other, and at one point when I expand a certain one, causing a series of messages to be sent up and down the parent/child chain, the above problem is occurring. Is there some kind of limit on the number of times a window procedure can be called recursively on the stack? On the number of sent messages a particular window can be processing at one time? There's definitely no logical error causing infinite recursion, the nesting is not extreme, perhaps about 15 child windows deep, if that. I'm simply starting at the base, requesting desired size information from the direct children (which they obtain recursively), then calling SetWindowPos() to resize them, and in response to the messages generated from this call, the child windows are then doing the same procedure themselves on their own child windows.
If anyone has any suggestions at all on what could be causing this, please let me know. I've run out of ideas, and patience. Thanks.
|
|
|
|
|
How can I display a message box that would disappear automatically on certain condtion.. I am not sure if I need a timer.... like the following code example
while( ! flag)
{
// I would like to show a message box here that will display as long as flag !=0 and disappear automatically when flag = 1;
if(condition)
flag = 1;
}
|
|
|
|
|
sabdalla80 wrote: How can I display a message box that would disappear automatically on certain condtion..
By reading here.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Wow, you are fast. Excellent !
|
|
|
|
|
The example shows how to pop up the message by clicking, how can I make it pop up under a condition without actually clicking on anything?
Thanks
|
|
|
|
|
What value did you use for the third argument to MessageBox() ?
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
I passed a NULL. After looking at the code, I think I know what to do...All I need to know was how and when to use WM_CLOSE.
I appreciate your help.
|
|
|
|
|
sabdalla80 wrote: I passed a NULL.
Why would you pass NULL when it expects a bool ? In any case, since NULL resolves to 0 , the MessageBox() function will treat that as false .
bclose - If this is set to true, the message box will close on its own after the delay period, otherwise the OK button is enabled so that the user can dismiss the message box manually.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Hi,
I am trying to get the logged on user info from 'Win32_LogonSession' Class. However when I try to get the 'Name' field from this Class I am getting NULL value in variable 'vtProp' at below line .
pclsObj->Get(L"Name", 0, &vtProp, 0, 0);
Below is the code snippet.
==================
HRESULT hres = WBEM_S_NO_ERROR;
IEnumWbemClassObject* pEnumerator = NULL;
hres = pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t("SELECT Name FROM Win32_LogonSession WHERE LogonType = 10"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
if (FAILED(hres))
{
//cout << "Query for operating system name failed."
// << " Error code = 0x"
// << hex << hres << endl;
pSvc->Release();
pLoc->Release();
return 1; // Program has failed.
}
IWbemClassObject *pclsObj;
ULONG uReturn = 0;
while (pEnumerator)
{
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1,
&pclsObj, &uReturn);
if(0 == uReturn)
{
ErrorInfo(hres,11);
break;
}
VARIANT vtProp;
// Get the value of the Name property
hr = pclsObj->Get(L"Name", 0, &vtProp, 0, 0);
printf(" Logged On User Name : %s",vtProp.bstrVal);
VariantClear(&vtProp);
}
====================
Regards,
Supriya Tonape.
modified on Wednesday, October 22, 2008 3:54 PM
|
|
|
|
|
Strange. I couldn't get any of the fields to return a non-null value. Can you use GetUserName() instead?
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
'GetUserName' returns user associated with the current thread only. I wanted to run my program on any host machine and get all usernames who are logged on that host machine n has active sessions...
|
|
|
|
|
Supriya Tonape wrote: I wanted to run my program on any host machine and get all usernames who are logged on that host machine...
Can you use NetWkstaUserEnum() ?
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Thanks but my requirement is that I have to get these names through WMI only. In fact after you told I tried API NetWkstaUserEnuma() and got Usernames too! but I donno whats gng wrong to not give me results...
|
|
|
|
|
any idea how can I get the username from {Win32_LogonSession.LogonId="50493851"} ? I am getting this though! I guess there shud be some way by using this ID I can get the required name. any suggestion ?
|
|
|
|
|
Supriya Tonape wrote: any idea how can I get the username from {Win32_LogonSession.LogonId="50493851"} ?
Try:
#include <ntsecapi.h>
#pragma comment(lib, "Secur32.lib")
...
LUID luid;
luid.HighPart = 0;
luid.LowPart = 50493851;
PSECURITY_LOGON_SESSION_DATA pLogonSessionData;
if (0 == ::LsaGetLogonSessionData(&luid, &pLogonSessionData))
{
::LsaFreeReturnBuffer(pLogonSessionData);
}
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|