ADO :: Adding Row, but changes not stored

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
 
T

TBass

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();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top