In my code to connect database successful but to insert data failed..
description failed : syntax error in INSERT INTO statement.
this is my code
#import <C:\\Program Files\\Common Files\\System\\ado\\msado15.dll> \ rename( "EOF", "AdoNSEOF" ) #include <iostream> #include <tchar.h> #include <windows.h> #include <stdio.h> using namespace std; // Data Access Method used in this sample const char* DAM = "ADO"; // Connection string for ADO _bstr_t bstrConnect = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\lat.mdb;"; int _tmain(int argc, _TCHAR* argv[]) { // Initialize the Component Object Module Library (COM) HRESULT hr = CoInitialize(NULL); if (FAILED(hr)) { cout<<DAM<<": Failed to CoInitialize() COM."<<endl; return hr; } // COM errors are handled by C++ try/catch block try { ADODB::_ConnectionPtr pConn("ADODB.Connection"); hr = pConn->Open(bstrConnect, "admin", "", ADODB::adConnectUnspecified); if (SUCCEEDED(hr)) { cout<<DAM<<": Successfully connected to database. Data source name:\n " <<pConn->GetConnectionString()<<endl; // Prepare SQL query. /*Initialize the values */ _bstr_t strName; _bstr_t strpass; strName = "'Darmawan',"; strpass = "'12345')"; /* Append the values to the Insert Statement */ _bstr_t strSQL("INSERT INTO Login(Username,Password) VALUES("); strSQL += strName + strpass; printf("%s\n",(LPCSTR)strSQL); //Execute the insert statement pConn->Execute((LPCSTR)strSQL,NULL,ADODB::adCmdText); printf("Data Added Successfully\n",(LPCSTR)strSQL); } else { cout<<DAM<<": Unable to connect to data source: "<<bstrConnect<<endl; } } catch(_com_error& e) { cout<<DAM<<": _com_error: "<<e.Description()<<endl; } // Release the Component Object Module Library (COM) CoUninitialize(); return hr; }
I also attached my database
Thank You...

Attached File(s)
-
lat.zip (9.97K)
Number of downloads: 50