Search code examples
c#strongly-typed-dataset

Adding rows to Strong Typed Dataset with relation


Hello got typed Dataset named DSMain.

Tables

User:
U_id int U_fname string U_lname string U_Case int

Case:
C_id int C_date string C_status int

U_Case is in relation with C_Status,

I want to add data to this table.

public static void AddNewDluznik(string fname, string lname, int case) { MainData.User.AddUserRow(fname, lname, case); }

Without rel it works.

Argument '3': cannot convert from 'int' to 'Zefir.DSMain.CaseRow'.


Solution

  • The way you are doing it, AddUserRow has the following signature:

    AddUserRow(string fName, string lName, CaseRow case) //note case is of type CaseRow, not int.
    

    You need to reference the CaseRow in your Case table to which your user is referencing:

    public static void AddNewDluznik(string fName, string lName, int case)
    {
        MainData.User.AddUserRow(fName, lName, MainData.Case.FindByC_id(case));
    }
    

    Alternatively, if you are working with isolated tables, and not the whole DataSet you can:

    public static void AddNewDluznik(string fName, string lName, int case)
    {
         var row = MainData.User.NewUserRow();
         row.U_fname = fName;
         row.U_lname = lName;
         row.U_Case = case; 
         MainData.User.AddUserRow(row);
    }