我有一个表,该表具有2个设置为FOREIGN键的变量,因此我可以从2个不同的表(ID和BrojIskaznice是FOREIGN键)中获取数据。如下面的代码所示,我试图在表'knjiga' and 'clanovi'
中引用FOREIGN键,但是由于某种原因,它没有获取值。我该如何解决?
MySqlConnection conn = new MySqlConnection("datasource=localhost;port=3306;username=root;password=6sPPFNy2;database=knjiznica");
conn.Open();
int ID = Int32.Parse(Microsoft.VisualBasic.Interaction.InputBox("Unesite ID knjige"));
int BrojIskaznice = Int32.Parse(Microsoft.VisualBasic.Interaction.InputBox("Unesite Broj iskaznice člana"));
MySqlCommand insertSQL = new MySqlCommand("INSERT INTO posudba (ID, BrojIskaznice) VALUES ('" + ID + "', '" + BrojIskaznice + "')", conn);
MySqlCommand insertNaziv = new MySqlCommand("INSERT INTO posudba (Naziv, Ime, Prezime) SELECT knjige.Naziv, clanovi.Ime, clanovi.prezime FROM knjige, clanovi WHERE (knjige.ID = '" + ID + "') AND (clanovi.BrojIskaznice = '" + BrojIskaznice + "')");
insertSQL.ExecuteNonQuery();