insert Foreign Key

  • Thread starter Thread starter Irfan
  • Start date Start date
I

Irfan

hi,
I am trying to insert data into an MSAccess table through a datagrid. I did
it by creating a custom Insert Command.
However, the table has a foreignKey,which obviously is hidden to the user
(mappingType.hidden) and i tried to pouplate it using the code below, before
running update

//// code in Update_Click button
If ds.HasChanges Then
Dim dt As DataTable = ds.Tables("codegrid").GetChanges(DataRowState.Added)
dt.Rows(0)("filenamefk") = 1 'assume only one row is added and fk =1
End If
///
da.update(ds,tbl)

I can see the table updated in Access but not the fileNamefk.
Is it the correct way to include the data that is not been inserted via
datagrid, but needs to be in table.
Is there any other way to do this.

TIA
Irfan
 
In a DataSet, there are a variety of different "states" held. When you
examine the DataSet, you have to ensure you are looking at the right "state"
to see the changes you employ. There is nothing wrong with updating a row
behind the scenes, but you will have to make sure the manual update is
properly processed if you wish to rebind the DataSet.

As to your question, the method you are using is fine. I would probably code
a bit different, but I am a control freak with data access. :-)

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
thanks Greg
I do understand that manual update is a bit doggy, but my questions still
remains:
How do u insert that part of a data that user dont need to enter but a
developer needs to insert it behind the scene.
for example, foreignKey in a child table

Anyideas will be appreciated
irfan
 
Back
Top