write Database error..

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2007
Posts: 16
Reputation: shizu is an unknown quantity at this point 
Solved Threads: 0
shizu shizu is offline Offline
Newbie Poster

write Database error..

 
0
  #1
Jan 14th, 2008
Hi..
I'm using VC6++ with window xp..
and my coding is like below..
  1. try
  2. {
  3. CString szConn;
  4.  
  5. hrResult = m_Connection.CreateInstance(__uuidof(Connection));
  6.  
  7. if(SUCCEEDED(hrResult))
  8. {
  9. szConn = "Provider=Microsoft.JET.OLEDB.4.0;Data
  10. source=C:\\PSMotion\\Database\\IO.mdb";
  11.  
  12. _bstr_t bstrConn(szConn);
  13. hrResult = m_Connection->Open(bstrConn,"Admin","",-1);
  14.  
  15. if(SUCCEEDED(hrResult))
  16. {
  17. _CommandPtr pCommandResult;
  18. _variant_t vtEmpty1(DISP_E_PARAMNOTFOUND,
  19. VT_ERROR);
  20. _variant_t vtEmpty2(DISP_E_PARAMNOTFOUND,
  21. VT_ERROR);
  22.  
  23. sprintf(sql,"DELETE * FROM IOList");
  24. _bstr_t bstrResult(sql);
  25. pCommandResult.CreateInstance(__uuidof(Command));
  26. pCommandResult->ActiveConnection =
  27. m_Connection.GetInterfacePtr();
  28. pCommandResult->CommandText = bstrResult;
  29. pCommandResult->Execute(&vtEmpty1, &vtEmpty2,
  30. adCmdText);
  31.  
  32. for(int i=0; i<m_poProperty->m_iTotalSignal; i++)
  33. {
  34. sprintf(sql,"INSERT INTO IOList (SignalName,
  35. Pattern, Port, Type, Address, Mapping)
  36. VALUES('%s','%s',%d,%d,'%s','%s')",
  37. m_poProperty->m_szMapping
  38. [i].szSignalName, m_poProperty-
  39. >m_szMapping[i].szPattern,
  40. m_poProperty->m_szMapping[i].iPort,
  41. m_poProperty->m_szMapping[i].bType,
  42. m_poProperty->m_szMapping
  43. [i].szAddress, m_poProperty-
  44. >m_szMapping[i].szName);
  45.  
  46. _bstr_t bstrResult(sql);
  47. pCommandResult.CreateInstance(__uuidof
  48. (Command));
  49. pCommandResult->ActiveConnection =
  50. m_Connection.GetInterfacePtr();
  51. pCommandResult->CommandText= bstrResult;
  52. [COLOR="Red"]pCommandResult->Execute
  53. (&vtEmpty1, &vtEmpty2, adCmdText);[/COLOR]
  54. }
  55.  
  56. pCommandResult.Release();
  57. }
  58. }
  59.  
  60. if(m_Connection)
  61. {
  62. m_Connection->Close();
  63. m_Connection.Release();
  64. }
  65. }
  66. // ** Error Checking
  67. catch(...)
  68. {
  69. if(m_Connection)
  70. {
  71. m_Connection->Close();
  72. m_Connection.Release();
  73. }
  74.  
  75. CWnd oWnd;
  76. oWnd.MessageBox("Open Database Error", "Database", MB_OK |
  77. MB_ICONSTOP);
  78. }
when coding comes to pCommandResult->Execute(&vtEmpty1, &vtEmpty2, adCmdText);, will jump to catch.., i don't know what happen on it..but only my PC will not happen this error. If i run this program in other PC, same error will prompt out..

pls advise..
regards,
shizu
Last edited by Narue; Jan 14th, 2008 at 9:38 am. Reason: Added code tags
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC