|
i also think so..then why it is not creating database table with 5 col....and inserting data in that...do you have any idea.....
|
|
|
|
|
And when you create your database why use open and also MoveNext you dont have any records except one
|
|
|
|
|
i also think so..then why it is not creating database table with 5 col....and inserting data in that...do you have any idea.....or can you say hoe to c mytable
|
|
|
|
|
CDaoDatabase database;
CDaoRecordset recordset(&database);
CString lpszFile = "c:\\Database2.mdb";
database.Create(lpszFile);
//database.Open(lpszFile);
CString SqlCmd = "CREATE TABLE MYTable (MarketNo VARCHAR(2),MarketName VARCHAR(8),Bid VARCHAR(10),Ask VARCHAR(10),MarketState VARCHAR(2))";
database.Execute(SqlCmd);
recordset.Open(AFX_DAO_USE_DEFAULT_TYPE,"SELECT * FROM MyTable",0);
database.Execute("INSERT INTO MyTable values('a','Market','b','c','d')");
//database.Execute("INSERT INTO MyTable(MarketName)");
//database.Execute("INSERT INTO MyTable(Bid)");
//database.Execute("INSERT INTO MyTable(Ask)");
//database.Execute("INSERT INTO MyTable(MarketState)");
recordset.AddNew();
recordset.SetFieldValue("MarketNo","2a");
recordset.SetFieldValue("MarketName","2Market");
recordset.SetFieldValue("Bid","2b");
recordset.SetFieldValue("Ask","2c");
recordset.SetFieldValue("MarketState","2d");
recordset.Update();
//recordset.MoveNext();
recordset.AddNew();
|
|
|
|
|
abrakadbra wrote: CString SqlCmd = "CREATE TABLE MYTable.mdb (MarketNo VARCHAR(2),MarketName VARCHAR(8),Bid VARCHAR(10),Ask VARCHAR(10),MarketState VARCHAR(2))";
Try removing the .mdb from your create table statement.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
Not sure exactly what your're trying to do, but your insert into statements don't look right.
To add records, you can either use insert into statements or recordset's addnew/update, but you don't need to do both.
database.Execute( "INSERT INTO MyTable(MarketNo, MarketName, Bid, Ask, MarketState) VALUES('1', 'myname', '123', '150', 'A')" );
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
ok...but i am not able to c mytable..it is not creating the table..why..
|
|
|
|
|
You might have more luck in the Database Forum http://www.codeproject.com/script/comments/forums.asp?forumid=1725[^], but I don't think Access understands the same column types as SQL (i.e. you might need to change the varchar() to Text or something).
Do you have Access installed? Try creating your database in Access, and then maybe you can figure out the correct create table statement.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
Why not wrap this code in a TRY /CATCH block to see why it is failing?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I seem to remember that you need to register the .mdb (forgot how to do it exactly), but I don't think you are going to have any luck until you register the database with Access. Or have things changed since my last foray into DBs about 5 years ago?
John P.
|
|
|
|
|
where can i get sample programs for serial communication using MFC?
|
|
|
|
|
|
|
Sometimes, while allocating memory in my programs, I get NULL in responce to call of new operator.
Sometimes, when I execute following pair of statements, I get Heap Error.
TCHAR * szText = new TCHAR[iLen * 7] ;
//... Some Code
delete [] szText ; // Causes heap error
Where and what I might be doing wrong?
Polite Programmer
More Object Oriented then C#
|
|
|
|
|
What is the value of iLen ? And what is the code missing between these two lines. You don't provide any valuable information for us to help you...
|
|
|
|
|
You are right, not enough information:
Value of iLen is > 0 < 200. Moreover, between the lines, we are just calling string manipulation functions like strlen, strcpy etc. But when the delete []szText is executed, heap corruption message follows....
Polite Programmer
More Object Oriented then C#
|
|
|
|
|
Can you post the exact code ? We cannot help if you don't provide meaningfull informations.
|
|
|
|
|
Polite Programmer wrote: between the lines, we are just calling string manipulation functions like strlen, strcpy etc.
What if these are omitted? Does the problem still exist? If not, it could be that you are writing outside of the allocated memory.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Polite Programmer wrote: I get NULL in responce to call of new operator.
Is this the problem?
Also try to use Safe String APIs instead of strcpy etc
S o h a i l K a d i w a l a
To Err Is Human; to Debug, Divine
modified 21-Apr-21 21:01pm.
|
|
|
|
|
Here is the full code, Comments starting with NOTE are the erroroneous...
<br />
#include <windows.h><br />
#include <tchar.h><br />
#include <stdio.h><br />
<br />
#include "resource.h"<br />
<br />
#include "convert.h"<br />
<br />
HWND hwndNextClipboardVierwer ;<br />
char * szInPageData ;<br />
HFONT hFont ;<br />
<br />
<br />
<br />
<br />
void DumpHex(TCHAR * szText, HWND hDlg)<br />
{<br />
int iLen = _tcsclen(szText) ;<br />
TCHAR szBuffer[10] ;<br />
<br />
<br />
TCHAR * szHexDump = new TCHAR[iLen * 7] ;<br />
<br />
ZeroMemory(szHexDump, iLen * 7) ;<br />
<br />
for(int i = 0 ; i < iLen ; i++)<br />
{<br />
wsprintf(szBuffer, _T("0x%X, "), szText[i]) ;<br />
_tcscat(szHexDump, szBuffer) ;<br />
}<br />
<br />
SetDlgItemText(hDlg, IDC_EDIT_UNIHEX, szHexDump) ;<br />
<br />
<br />
delete [] szHexDump ;<br />
}<br />
<br />
BOOL CALLBACK DlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)<br />
{<br />
HANDLE hMemory = NULL;<br />
TCHAR * szUnicodeText = NULL ;<br />
char * lptstr = NULL ;<br />
int iLen = NULL ;<br />
<br />
switch(msg)<br />
{<br />
case WM_INITDIALOG:<br />
<br />
hwndNextClipboardVierwer = SetClipboardViewer(hWnd) ;<br />
hFont = CreateFont( 80,<br />
80,<br />
0,<br />
0,<br />
0,<br />
0,<br />
0,<br />
0,<br />
0,<br />
0,<br />
0,<br />
0,<br />
0,<br />
_T("Pak Nastaleeq")) ;<br />
SendDlgItemMessage(hWnd, IDC_EDIT_UNICODE, WM_SETFONT, (WPARAM) hFont, TRUE) ;<br />
return FALSE ;<br />
<br />
case WM_DRAWCLIPBOARD:<br />
<br />
if(OpenClipboard(hWnd))<br />
{<br />
hMemory = GetClipboardData(CF_TEXT) ;<br />
lptstr = (char *) GlobalLock(hMemory) ;<br />
<br />
if(hMemory == NULL || lptstr == NULL)<br />
{<br />
CloseClipboard() ;<br />
return FALSE ;<br />
}<br />
<br />
iLen = strlen(lptstr) ;<br />
szInPageData = new char[iLen + 1] ;<br />
szUnicodeText = new TCHAR[(iLen / 2) + (iLen / 100) * 10] ;<br />
strcpy(szInPageData, lptstr) ;<br />
GlobalUnlock(hMemory) ;<br />
<br />
SendMessage(hwndNextClipboardVierwer, msg, wParam, lParam) ;<br />
ConvertInPageToUncode(szInPageData, iLen, szUnicodeText) ;<br />
DumpHex(szUnicodeText, hWnd) ;<br />
SetDlgItemText(hWnd, IDC_EDIT_UNICODE, szUnicodeText) ;<br />
<br />
delete [] szInPageData ;<br />
<br />
delete [] szUnicodeText ;<br />
<br />
<br />
}<br />
<br />
<br />
return TRUE ;<br />
<br />
case WM_COMMAND:<br />
switch(LOWORD(wParam))<br />
{<br />
case IDOK:<br />
EndDialog(hWnd, 1) ;<br />
break ;<br />
case IDCANCEL:<br />
EndDialog(hWnd, 0) ;<br />
break ;<br />
<br />
}<br />
return TRUE ;<br />
<br />
case WM_DESTROY:<br />
ChangeClipboardChain(hWnd, hwndNextClipboardVierwer) ;<br />
return TRUE ;<br />
}<br />
<br />
return FALSE ;<br />
}<br />
<br />
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,<br />
LPTSTR lpCmdLine, int nCmdShow)<br />
{<br />
DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DlgProc) ;<br />
return 0 ;<br />
}
Polite Programmer
More Object Oriented then C#
|
|
|
|
|
Polite Programmer wrote: void DumpHex(TCHAR * szText, HWND hDlg)
{
int iLen = _tcsclen(szText) ;
TCHAR szBuffer[10] ;
/*NOTE: This call fails i.e. returns NULL (even iLen is > 0)*/
TCHAR * szHexDump = new TCHAR[iLen * 7] ;
ZeroMemory(szHexDump, iLen * 7) ;
for(int i = 0 ; i < iLen ; i++)
{
wsprintf(szBuffer, _T("0x%X, "), szText[i]) ;
_tcscat(szHexDump, szBuffer) ;
}
/*NOTE: This Call generates Heap corruption message from CRT*/
delete [] szHexDump ;
}
This is the code snippet that you need to focus on. What is the value of ilen ? What does szBuffer look like each iteration of the loop? How are you verifying that szHexDump is big enough for iLen concatenations?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I think you are mixing to many types of chars (i.e TCHARs, chars and LPSTRs). I think u have a confusion regarding there usage. First of all from ur code....
TCHAR *szUnicodeText = new TCHAR[(iLen / 2) + (iLen / 100) * 10] ;
you give an impression that TCHAR == Unicode character???? this is a wrong assumption. The definition of TCHARs can be found in headers its something like
<br />
#if defined _UNICODE<br />
#define TCHAR WCHAR<br />
#else<br />
#define TCHAR CHAR<br />
#enif<br />
so depending upon your build type (unicode or ansi) the type and hence the size of the TCHARs changes.
I think you are trying to make some sort of clipbroard viewer to display the unicode and hex value of the data on the clipboard.
try using this code instead in your DrawClipboard notification
<br />
if(OpenClipboard())<br />
{<br />
HANDLE hMemory = GetClipboardData(CF_TEXT) ;<br />
TCHAR *lptstr = (TCHAR*) GlobalLock(hMemory) ;<br />
<br />
if(hMemory == NULL || lptstr == NULL)<br />
{<br />
CloseClipboard() ;<br />
}<br />
<br />
int iLen = _tcslen(lptstr) ;<br />
TCHAR *szInPageData = new TCHAR[iLen + 1] ;<br />
_tcscpy(szInPageData, lptstr) ;<br />
USES_CONVERSION;<br />
LPWSTR szUnicodeText = T2W(szInPageData);<br />
GlobalUnlock(hMemory) ;<br />
<br />
::SendMessage( hNextViewer, WM_DRAWCLIPBOARD, 0, 0 ) ;<br />
DumpHex( W2T(szUnicodeText), GetSafeHwnd()) ;<br />
<br />
delete [] szInPageData ;<br />
}<br />
Trust me, nothing's impossible!
|
|
|
|
|
Polite Programmer wrote: //... Some Code
Is it possible that "//... Some Code" writes more than iLen * 7 into szText?
I.e. the terminating '\0' character?
Or that "//... Some Code" causes a corrupted stack?
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
I'm sure it does'nt write past iLen * 7 but I'm not sure whether it can corrupt the stack. Please tell me how code can corrupt the stack? (Becuase I really dont know if the question seem stupid)
Polite Programmer
More Object Oriented then C#
|
|
|
|
|
Hello.
IMO, The usual reason for stack corruption is this:
foo
{
char text[5];
strcpy(text, "Hello");
}
text is a stack variable of 5 chars, but the strcpy() copies 6 bytes to it.
The last character written (the '\0' byte) will be written outside the boundry of text.
******** THIS IS A SIMPLIFIED EXPLANATION ********
The return address (to the function that called foo()) is also saved on the stack.
When the function foo returns, the return address is picked up from the stack. But a part of the return address is now overwritten by the the '\0' byte, and is altered.
So the program retuns to the wrong address, causing the program to go bananas.
That's stack corruption.
-- modified at 3:06 Wednesday 27th September, 2006
But you can get a lot of different fishy behaviour from stack corruption. It depends how the compiler uses the stack. It doesn't have to result in wrong return address, other things can happen, such as another stack variable suddenly changes its value, e.t.c.
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|