Darryn
After you have added the new row, you need to call the Update method of the
DataAdaptor
Do not call AcceptChanges (this marks the row as 'unchanged' so when Update
is called, there are no 'new' rows to write back to the database!)
The Update method, if successful will in effect call AcceptChanges anyway
Stephen
"Darryn Ross" <(E-Mail Removed)> wrote in message
news:%23j$pVo%(E-Mail Removed)...
> Hi,
>
> I am having trouble saving my new record to my access database, the
dataset
> gets updated fine but the new record is not being added to the database
for
> which it is looking at. Here is my code, any help would be appreciated.
>
> DtlsConnection.ConnectionString = strConnectionPath ;
> DtlsConnection.Open() ;
>
> SelectDtlsCommand.CommandText = "Select * From tble" ;
> SelectDtlsCommand.Connection = DtlsConnection ;
> DtlsAdapter.SelectCommand = SelectDtlsCommand ;
> DtlsAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey ;
> DtlsAdapter.Fill(DtlsDs, "tble") ;
>
> DataRow tblRow ;
> DataTable tbl ;
> tbl = DtlsDs.Tables["tble"] ;
> tblRow = tbl.NewRow() ;
>
> try {
> tblRow["Code"] = txtCode.Text ;
> tblRow["Name"] = txtName.Text ;
> tblRow["Type"] = txtType.Text ;
> tbl.Rows.Add(tblRow) ;
> DtlsDs.AcceptChanges() ;
> }
> catch(Exception e) {
> MessageBox.Show(e.Message, "Error Saving Data", MessageBoxButtons.OK,
> MessageBoxIcon.Error) ;
> }
>
>
> Kind Regards
> Darryn Ross
>
>
|