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
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
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
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
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
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
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
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