ADO :: Adding Row, but changes not stored

  • Thread starter Thread starter TBass
  • Start date Start date
T

TBass

After successfully creating a connection to an Access Database file on
my computer, I try to add a new row. Everything seems to go fine, but
when I open the file in Access, the row isn't there. I get no errors
or exceptions while running. In the code below, you can see I go back
and check if the data is in the table after I've added it, and it is.
Still, it's never stored permanently. Obviousy, I'm missing some
steps. Can anyone point me in the right direction?


m_dbConnection = gcnew OleDbConnection("Provider=Microsoft.Jet.OLEDB.
4.0;" +
"DataSource=" + szDataPath);

/* returns an empty dataset but with the correct structure */
sa->Fill( ds, "serial" );

DataTable ^m_pTable = ds->Tables["serial"];

DataRow ^pNewRow = m_pTable->NewRow();
pNewRow["SerialNum"] = szSerial;

m_pTable->Rows->Add( pNewRow );

pNewRow->AcceptChanges();

sa->Update( ds, "serial" );

array<DataRow ^> ^aRow = ds->Tables["serial"]->Select();

int i;
for( i=0; i<aRow->Length; ++i )
{
/* SHOWS THE VALUE I ADDED! */
MessageBox::Show( Convert::ToString( aRow["SerialNum"] ) );
}


m_dbConnection->Close();


Thanks in advance,
T
 
Here's what I ended up doing to make it work, should anyone have a
similar problem:

/*
* INSERT (OR DO ANYTHING) USING SQL COMMANDS
*/


String ^insertSQL = gcnew String("INSERT INTO serial (SerialNum)
VALUES( '" + szSerial + "' );");
OleDbCommand ^command = gcnew OleDbCommand(insertSQL);
command->Connection = m_dbConnection;

m_dbConnection->Open();
command->ExecuteNonQuery();


m_dbConnection->Close();
 
Back
Top