Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
S

Stefan Baens

@Stefan Baens
About
Posts
7
Topics
3
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • how to get the primary key for a new row
    S Stefan Baens

    I checked out the site and found the things I need I think. Just pity that microsoft provides only examples in VB and C#.

    Stefan

    Managed C++/CLI database help tutorial question announcement

  • how to get the primary key for a new row
    S Stefan Baens

    I have been looking at different site and manuals for an example but have not found one containing a stored procedure. Mostly I found some SQL way to find it but it has the same problem. Strange thing is that only the first time is not working and I can't find any missing declarations.

    Stefan

    Managed C++/CLI database help tutorial question announcement

  • how to get the primary key for a new row
    S Stefan Baens

    I have problem retrieving the primary key for a new row that is added to the database. This is what I have now:

    	// 9. Nieuwe rij maken in tabel
    	DataTable^ MyTable = myDataSet->Tables\[0\];
    	DataRow^ row = MyTable->Rows->Add();
    	if (row != nullptr)
    
    	{
    		// 10. Datavelden invullen
    		row\["item\_id"\] = item\_id;
    		row\["use"\] = use;
    		row\["type"\] = Convert::ToInt16(type);
    
    		// 11. Data updaten + Primary Key opvragen
    		DataAdapter->Update(myDataSet, "tblPanel");
    		PanelID = Convert::ToInt64(row\["ID"\]);
    	}
    

    now the value PanelID is always 0 for the first time this loop runs, the second time and further the information is correct and I can use the PanelID to create the relation with other tables. What am I missing?

    Stefan

    Managed C++/CLI database help tutorial question announcement

  • Write to Access Database using C++ and OleDB connection
    S Stefan Baens

    I finally found the error that prevented me from adding the data. I have used this code:

    DataTable^ MyTable = myDataSet->Tables[0];
    DataRow^ row = MyTable->Rows->Add();

    instead of this:

    DataRow^ row = myDataSet->Tables["tblPanel"]->NewRow();

    Stefan

    Managed C++/CLI database csharp c++ visual-studio com

  • Write to Access Database using C++ and OleDB connection
    S Stefan Baens

    This still does not work, i added it in between the other code. I now get exception for e { "Index was outside the bounds of the array."} Is there maybe a good example to write information to an access database using C++. I have found many examples but cannot find any that works in my project.

    	DataRow^ row = myDataSet->Tables\["tblPanel"\]->NewRow();
    	myDataSet->Tables\["tblPanel"\]->Rows->Add(row);
    	if (row != nullptr)
    	{
    		// 8. Datavelden invullen
    		row\["ID"\] = dblID;
    		row\["item\_id"\] = item\_id;
    		row\["use"\] = use;
    		row\["type"\] = Convert::ToInt16(type);
    		// dblID = Convert::ToDouble(row\["ID"\]);
    
    		// 9. Data updaten
    		DataAdapter->Update(myDataSet, "tblPanel");
    	}
    

    Stefan

    Managed C++/CLI database csharp c++ visual-studio com

  • Write to Access Database using C++ and OleDB connection
    S Stefan Baens

    I am trying to put information in an access database file (mdb) with an oledb connection. Everything seems fine but no new information is added to the database at the end. This is the code I have now:

    double Tabel_Panelinfo(String^ item_id, String^ use, String^ type)
    {
    // returnwaarde initialiseren
    int dblID = 10;

    // Aanmaken logische naam voor connectie
    OleDbConnection^ myOleDbConnection = nullptr;
    try
    {
        // 1. Build OLE DB connection string for MS Access database
        OleDbConnectionStringBuilder^ connectionBuilder = gcnew OleDbConnectionStringBuilder();
        connectionBuilder->Provider = "Microsoft.Jet.OLEDB.4.0";
        connectionBuilder->DataSource = "D:\\\\Data\\\\Visual Studio 2005\\\\Projects\\\\VertexBDXML-RandekSPL728\\\\VertexBDXML-RandekSPL728\\\\Tabel-XML.mdb";
        
        // 2. Create OLE DB connection
        myOleDbConnection = gcnew OleDbConnection(connectionBuilder->ToString());
        
        // 3. Open OLE DB connection
        myOleDbConnection->Open();
    
    	// 4. create OLE DB DataAdapter
    	OleDbDataAdapter^ DataAdapter = gcnew OleDbDataAdapter("SELECT \* FROM tblPanel", myOleDbConnection);
    
        // 4a. Attach FillError and RowUpdated event handlers
        DataAdapter->FillError += gcnew FillErrorEventHandler(MyEventHandler::FillError);
        DataAdapter->RowUpdated += gcnew OleDbRowUpdatedEventHandler(MyEventHandler::RowUpdated);
    
        // 5. Create DataSet
        DataSet^ myDataSet = gcnew DataSet();
    
    	// 6. Dataset opvullen
    	DataAdapter->MissingSchemaAction = MissingSchemaAction::Add;
        DataAdapter->Fill(myDataSet, "tblPanel");
    
    	// 7. Waarde zoeken
    	DataRow^ row = myDataSet->Tables\["tblPanel"\]->NewRow();
    	// DataRow^ row = myDataSet->Tables\["tblPanel"\]->Rows->Find("1");
    	if (row != nullptr)
    	{
    		// 8. Datavelden invullen
    		// row\["ID"\] = dblID;
    		row\["item\_id"\] = item\_id;
    		row\["use"\] = use;
    		row\["type"\] = Convert::ToInt16(type);
    		// dblID = Convert::ToDouble(row\["ID"\]);
    
    		// 9. Data updaten
    		DataAdapter->Update(myDataSet, "tblPanel");
    	}
    }
    catch(Exception^ e)
    {
    	Console::WriteLine(e->Message);
    }
    finally
    {
        // Close OLE DB connection
        if ( myOleDbConnection != nullptr )
            myOleDbConnection->Close();
    }
    
    return dblID;
    

    }

    Stefan

    Managed C++/CLI database csharp c++ visual-studio com

  • Write to Access Database using C++ and OleDB connection [modified]
    S Stefan Baens

    I am trying to put information in an access database file (mdb) with an oledb connection. Everything seems fine but no new information is added to the database at the end. This is the code I have now:

    double Tabel_Panelinfo(String^ item_id, String^ use, String^ type)
    {
    // returnwaarde initialiseren
    int dblID = 10;

    // Aanmaken logische naam voor connectie
    OleDbConnection^ myOleDbConnection = nullptr;
    try
    {
        // 1. Build OLE DB connection string for MS Access database
        OleDbConnectionStringBuilder^ connectionBuilder = gcnew OleDbConnectionStringBuilder();
        connectionBuilder->Provider = "Microsoft.Jet.OLEDB.4.0";
        connectionBuilder->DataSource = "D:\\\\Data\\\\Visual Studio 2005\\\\Projects\\\\VertexBDXML-RandekSPL728\\\\VertexBDXML-RandekSPL728\\\\Tabel-XML.mdb";
        
        // 2. Create OLE DB connection
        myOleDbConnection = gcnew OleDbConnection(connectionBuilder->ToString());
        
        // 3. Open OLE DB connection
        myOleDbConnection->Open();
    
    	// 4. create OLE DB DataAdapter
    	OleDbDataAdapter^ DataAdapter = gcnew OleDbDataAdapter("SELECT \* FROM tblPanel", myOleDbConnection);
    
        // 4a. Attach FillError and RowUpdated event handlers
        DataAdapter->FillError += gcnew FillErrorEventHandler(MyEventHandler::FillError);
        DataAdapter->RowUpdated += gcnew OleDbRowUpdatedEventHandler(MyEventHandler::RowUpdated);
    
        // 5. Create DataSet
        DataSet^ myDataSet = gcnew DataSet();
    
    	// 6. Dataset opvullen
    	DataAdapter->MissingSchemaAction = MissingSchemaAction::Add;
        DataAdapter->Fill(myDataSet, "tblPanel");
    
    	// 7. Waarde zoeken
    	DataRow^ row = myDataSet->Tables\["tblPanel"\]->NewRow();
    	// DataRow^ row = myDataSet->Tables\["tblPanel"\]->Rows->Find("1");
    	if (row != nullptr)
    	{
    		// 8. Datavelden invullen
    		// row\["ID"\] = dblID;
    		row\["item\_id"\] = item\_id;
    		row\["use"\] = use;
    		row\["type"\] = Convert::ToInt16(type);
    		// dblID = Convert::ToDouble(row\["ID"\]);
    
    		// 9. Data updaten
    		DataAdapter->Update(myDataSet, "tblPanel");
    	}
    }
    catch(Exception^ e)
    {
    	Console::WriteLine(e->Message);
    }
    finally
    {
        // Close OLE DB connection
        if ( myOleDbConnection != nullptr )
            myOleDbConnection->Close();
    }
    
    return dblID;
    

    }

    -- modified at 5:47 Friday 24th August, 2007 -- modified at 5:47 Friday 24th August, 2007 Stefan -- modified at 5:48 Friday 24th August, 2007

    C / C++ / MFC database csharp c++ visual-studio com
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups