0

I am having trouble with my code. I want to update information in an access database but it keeps catching an error at the line conn->Open and does not give any information into what the error is.

cout << "Please enter file name... ";
cin >> fileName;
String^ name = gcnew String(fileName.c_str());
String^ sqlstr = "UPDATE [Saved] SET Name = '"+name+"' WHERE ID = 1";   
OleDbConnection^ conn = nullptr;
OleDbCommand^ cmd = nullptr;

try {
    //Create and open database connection.
    conn = gcnew OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = F:\WWTMrWolf_Prototype_Demo\Debug\WTMrWolf_P_D_Database.mdb");
    conn->Open();
    cmd = gcnew OleDbCommand(sqlstr, conn);
    OleDbDataReader^ reader = cmd->ExecuteReader(System::Data::CommandBehavior::CloseConnection);
    while (reader->Read())
    {
        printf("File ") +reader["Name"]->ToString()+ (" created");
    }

}
catch (Exception^ ex)
{
    printf("Error: ") + ex->ToString();
    system("Pause");
    exit(0);
}
return fileName;

Output: "Error: Press any key to continue..."

James
  • 13
  • 3
  • This isn't c++. It looks like c++/cli to me. – François Andrieux Feb 22 '18 at 19:53
  • Is the output coming from the catch-block? – Xan-Kun Clark-Davis Feb 22 '18 at 20:08
  • `printf("Error: ") + ex->ToString();`: you'll have a lot better luck if you use `Console::WriteLine`, and put `+ex->ToString()` *inside* the parentheses. – David Yaw Feb 22 '18 at 20:09
  • Thanks, the error message responded starting with the line System.InvalidOperationException: The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine. James 4 mins ago – James Feb 22 '18 at 20:13
  • Sounds like you need to install something. Either that or you've got the 32/64 bit issue mentioned here: https://stackoverflow.com/questions/1991643/microsoft-jet-oledb-4-0-provider-is-not-registered-on-the-local-machine – David Yaw Feb 22 '18 at 20:39
  • I'm making this on Visiual Studio 2015 and that provider has worked using c# in a previous project. – James Feb 22 '18 at 21:18
  • If that provider works in C#, then it's probably a 32/64 bit issue. Maybe you're compiling C++/CLI as 32-bit and that provider is only installed as 64-bit. – David Yaw Feb 22 '18 at 21:58
  • After a bit of tampering it has now come out with is error: system.invalidoperationexception <0x80004005> could not find file F:\WWTMrWolf_Prototype_Demo\WWTMrWolf_Prototype_Demo\WWTMrWolf_Prototype_DemoDebugWTMrWolf_P_D_Database.mdb – James Feb 24 '18 at 23:24

0 Answers0