locked
Inserting a row into a relational database RRS feed

  • Question

  • Hi There,

    I am having a problem inserting a row into a table in my database that has a foreign key.

    I have two tables: "Devices" and "Interfaces".  The "Interfaces" Table contains a foreign key of "DeviceID" to support the One to Many relationship between the two tables (One Device can have Many Interfaces).  However, when i come to create a new row int the "Interfaces" table i do not know how to insert the foreign key.  My Primary Keys in each table are integer values so i tried just putting an integer value in the IntacesTable.addInterfacesRow() method.  However i get the following error message:

    Error 2 Argument '2': cannot convert from 'int' to 'NetAssessor.NetworkMapDataDataSet.DevicesRow' C:\Users\Mark\Documents\Visual Studio 2008\Projects\NetAssessor\NetAssessor\Forms\Processing.cs 92 111 NetAssessor.

    Now this i can see is because the two datatypes dont match.  One is Int and one is DevicesRow.  So i am pressuming there is something i need to do to be able to insert the foreign key integer value.

    Some Additional Info to note is that i built the database as a .mdf file in Visual Studio 2008, i have created the relationships correctly too.

    Any Help is very much appreciated :)


    M.Fellows
    Saturday, April 10, 2010 9:08 AM

Answers

  • You can find the related device row then pass it like...
    IntacesTable.addInterfacesRow(field1, field2, yourDataSet.DevicesTable.FindById(intDeviceId), fieldK,..., fieldN);
    • Marked as answer by deviao9 Saturday, April 10, 2010 9:57 AM
    Saturday, April 10, 2010 9:14 AM

All replies

  • You can find the related device row then pass it like...
    IntacesTable.addInterfacesRow(field1, field2, yourDataSet.DevicesTable.FindById(intDeviceId), fieldK,..., fieldN);
    • Marked as answer by deviao9 Saturday, April 10, 2010 9:57 AM
    Saturday, April 10, 2010 9:14 AM
  • HI there,

    That is exactly what i was looking for! thank you very much :)


    M.Fellows
    Saturday, April 10, 2010 9:57 AM