TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Akhter HUssain
720
1.3k
101.3k
FK conflict occurred
Dec 19 2018 4:30 AM
This error is coming
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_SubDepartment_SubDepartment". The conflict occurred in database "AttendanceManagement", table "dbo.Department", column
protected
void
Page_Load(
object
sender, EventArgs e)
{
{
con =
new
SqlConnection(
"Data Source=IT;Integrated Security=SSPI;Initial Catalog=AttendanceManagement"
);
using
(SqlCommand cmd =
new
SqlCommand(
"SELECT DeptID, DeptName FROM Department"
))
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
DropDownList1.DataSource = cmd.ExecuteReader();
DropDownList1.DataTextField =
"DeptName"
;
DropDownList1.DataValueField =
"DeptID"
;
DropDownList1.DataBind();
con.Close();
}
}
DropDownList1.Items.Insert(0,
new
ListItem(
"--Select Customer--"
,
"0"
));
}
protected
void
Button1_Click(
object
sender, EventArgs e)
{
string
DeptName = txtsubdept.Text;
string
DeptID = DropDownList1.SelectedValue;
string
query =
"INSERT INTO SubDepartment VALUES(@DeptName,@DeptID)"
;
con =
new
SqlConnection(
"Data Source=IT;Integrated Security=SSPI;Initial Catalog=AttendanceManagement"
);
{
using
(SqlCommand cmd =
new
SqlCommand(query))
{
cmd.Parameters.AddWithValue(
"@DeptName"
, DeptName);
cmd.Parameters.AddWithValue(
"@DeptID"
, DeptID);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
Reply
Answers (
1
)
how to save automatically in forms in razor(mvc)?
Make an API that sends the data depending upon client device