Hi
I have wrote this code
SqlConnection con = new SqlConnection("Data Source=MOSTAFA;Initial Catalog=mohasba;Integrated Security=True");
SqlCommand com = new SqlCommand("insert into Ezn_Qaid (Qaid_no,Qaid_date,Maden,Dayn,El_Qema,Qaid_Type,Bayan_Oll) values('" + B_No.Text + "','" + B_Date.Text + "','" + B_m.Text + "','" + B_D.Text + "','" + B_Q.Text + "','" + comboBox3.SelectedIndex + "','" +comboBox1.SelectedIndex+ "')", con);
con.Open();
com.ExecuteNonQuery();
and get the following erorr
The INSERT statement conflicted with the FOREIGN KEY constraint "FK__Ezn_Qaid__Bayan___44FF419A". The conflict occurred in database "mohasba", table "dbo.Bayan", column 'byan_name'.
The statement has been terminated.
Note
the database
create table Ezn_Qaid
(
Qaid_no nvarchar(20) ,
Qaid_date nvarchar(10) ,
Maden float ,
Dayn float,
El_Qema float,
Qaid_Type nvarchar(15) ,
--byan_name int NOT NULL, -- this is the new column
Bayan_Oll nvarchar(100) FOREIGN KEY (Bayan_Oll) REFERENCES Bayan(byan_name ),
Bayan_Bank nvarchar(100) FOREIGN KEY (Bayan_Bank ) REFERENCES Bank(byan_name ),
Bayan_3momya nvarchar(100) FOREIGN KEY (Bayan_3momya) REFERENCES msaref_3momya(byan_name ),
Bayan_Tkalef nvarchar(100) FOREIGN KEY (Bayan_Tkalef) REFERENCES tkalef_nshat (byan_name )
)
create table Bayan
(
byan_no int identity ,
byan_name nvarchar(100)PRIMARY KEY
)
The column byan_name contain only one record "Visa" and the combobox item contain "Visa"
Thanks