I am trying to insert data into the table 'table' , but I am stocked with the error of foreign key , 'building_id' from the building table , how do I get through it?
Error prompt:
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_user_user".
The conflict occurred in database "C:\USERS\USER\DOWNLOADS\VIUSAL\VIUSAL\ENERGYVIUSAL\ENERGYVIUSAL\DATABASE1.MDF", table "dbo.building", column 'building_id'. The statement has been terminated.
This is the code:
DataRow drowEmployee = dsetEnergyViusal.Tables["Table"].NewRow();
drowEmployee["Name"] = txtName.Text;
drowEmployee["ContactID"] = Convert.ToInt32(txtContactId.Text);
drowEmployee["Company"] = txtCompanyId.Text;
drowEmployee["Building_id"] = txtBuildingID.Text;
drowEmployee["Telephone"] = txtContactNumber.Text;
drowEmployee["Email"] = txtEmail.Text;
drowEmployee["Password"] = txtPassword.Text;
if (radClient.Checked)
drowEmployee["Client"] = radClient.Checked;
else if (radNews.Checked)
drowEmployee["News"] = radNews.Checked;
drowEmployee["Telephone"] = txtContactNumber.Text;
dsetEnergyViusal.Tables["Table"].Rows.Add(drowEmployee);
sqldaEnergyViusal.Update(dsetEnergyViusal, "Table");
MessageBox.Show("Record has been successfully added.", "EnergyViusal", MessageBoxButtons.OK, MessageBoxIcon.Information);
User_register_Load(null, null);