Model-relational in firebird with C #

3

Developing a small C # project with Visual Studio, firebird and ibexpert. With the tables NOT RELATIONSHIP I run everything right. But I need to relate CLIENTE 1: N to BONUS E SAIDA . I am not able to develop the following reasoning:

I have a table named: CLIENTE with ID_CLIENTE (Primary Key), ID_BONUS (FOREIGN Key), ID_SAIDA (FOREIGN Key), NOME and Data .

Table BONUS with ID_BONUS (Primary key), data , time1 , hora2 , total . Table SAIDA with ID_SAIDA (Foreign Key), data , hora1 , hora2 , total .

A Form1 for CLIENTE with DATAGRID and another Form2 for BONUS E SAIDA (2 DATAGRID).

Should I put textbox for the foreign keys in CLIENTE ? And how can I call Form2, is the primary key of BONUS and SAIDA ?

My code has no relationship: 1 button search on Form1 and a button that accesses Form2.

string mSQL = "Select * from CLIENTE Where ID_CLIENTE = " + id;
    
asked by anonymous 23.09.2014 / 05:02

1 answer

6

I think you changed the balls, the foreign keys always stay on the N side.

Your tables would look something like this:

client table

  • customer_id (primary key)
  • name
  • data

bonus table

  • char_id (foreign key, customer_id reference)
  • data
  • hora1
  • hora2
  • total

table output

  • external_id (foreign key, customer_id reference)
  • data
  • hora1
  • hora2
  • total

Depending on your business rule, you may even ask the user to put the foreign key, but this is not recommended as it opens many loopholes for failures. Ideally, when you sign up for a new bonus / exit, make a select of the primary key of the user from the data you already have on it in the application.

Tip: Do not concatenate a variable with a query , always use parameterized commands.

    
23.09.2014 / 05:24