when i change the menumasterid data type to varchar then i had a foll.error.
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_UserCreation_MenuMaster1". The conflict occurred in database "Live proj", table "dbo.MenuMaster", column 'MenuMasterID'.
The statement has been terminated.
my team leader told exactly what you are telling.they told me to delete that mastermenuid from new user creation table.i m confused how can i fetch id?pls help me tdmca..
pls see the below post..to get idea about my tables.i want at time of user creation assign the authorization.using this user can see only checked pages..
so i write blow code on create button..
also i am attaching the screen shot of my page to get better idea...
protected void btnCreate_Click(object sender, EventArgs e)
{
string s = "";
foreach (ListItem listItem in chkMenurights.Items)
{
if (listItem.Selected == true)
{
SqlCommand cmd1 = new SqlCommand("insert into MenuUserRights values(@MenuMasterId)");
}
}
SqlConnection con = new SqlConnection(strConnection);
con.Open();
cmd = new SqlCommand("Insert Into UserCreation(FullName,UserName,Email,PhoneNo,RegionID,StateId,CityID,Password,MenuRightsID) VALUES(@FullName,@UserName,@Email,@PhoneNo,@RegionID,@StateId,@CityID,@Password,@MenuRightsID)", con);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@FullName", txtName.Text);
cmd.Parameters.AddWithValue("@UserName", txtUsername.Text);
cmd.Parameters.AddWithValue("@Email", txtEmail.Text);
cmd.Parameters.AddWithValue("@PhoneNo", txtPhone.Text);
cmd.Parameters.AddWithValue("@RegionID", ddlRegion.SelectedValue);
cmd.Parameters.AddWithValue("@StateId", ddlState.SelectedValue);
cmd.Parameters.AddWithValue("@CityID", ddlCity.SelectedValue);
cmd.Parameters.AddWithValue("@Password", txtPassword.Text);
cmd.Parameters.AddWithValue("@MenuRightsID",chkMenurights.SelectedValue);
cmd.ExecuteNonQuery();
con.Close();
ClientScript.RegisterStartupScript(this.GetType(), "Hello", "alert('Successfully created a user');", true);
txtName.Text = "";
txtUsername.Text = "";
txtEmail.Text = "";
txtPhone.Text = "";
txtPassword.Text = "";
ddlRegion.SelectedIndex = 0;
ddlState.SelectedIndex = 0;
ddlCity.SelectedIndex = 0;
}
if u have team viwer software then tell me i will show online..
apurva16
Member
21 Points
87 Posts
Re: how to save checked item into database.
Apr 11, 2012 05:00 AM|LINK
when i change the menumasterid data type to varchar then i had a foll.error.
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_UserCreation_MenuMaster1". The conflict occurred in database "Live proj", table "dbo.MenuMaster", column 'MenuMasterID'.
The statement has been terminated.
pls telll me now..
apurva16
Member
21 Points
87 Posts
Re: how to save checked item into database.
Apr 11, 2012 06:12 AM|LINK
Hi,
my team leader told exactly what you are telling.they told me to delete that mastermenuid from new user creation table.i m confused how can i fetch id?pls help me tdmca..
thanx.
sanjayverma_...
Participant
1456 Points
345 Posts
Re: how to save checked item into database.
Apr 11, 2012 09:56 AM|LINK
cmd.Parameters.AddWithValue("@MenuMasterID",chkmenuRights.SelectedValue);this will give the id which bind with the checkbox.
tdmca
Contributor
2396 Points
661 Posts
Re: how to save checked item into database.
Apr 11, 2012 10:08 AM|LINK
i think you have to create new id, insert into main table
now in rights table use this id as a foreign key for multiple rights
sriramabi
Contributor
4351 Points
1277 Posts
Re: how to save checked item into database.
Apr 11, 2012 10:09 AM|LINK
hi
u like try this
foreach (ListItem listItem in chkmenuRights.Items) { if (listItem.Selected == true) { int IsChecked=true; if(chkmenuRights.Checked==True) { IsChecked=true; } SqlConnection con = new SqlConnection(strConnection); con.Open(); cmd = new SqlCommand("Insert Into UserCreation(FullName,UserName,Email,PhoneNo,RegionID,StateId,CityID,Password,SecurityQue,SecurityAns,MenuMasterID) VALUES(@FullName,@UserName,@Email,@PhoneNo,@RegionID,@StateId,@CityID,@Password,@SecurityQue,@SecurityAns,@MenuMasterID)", con); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@FullName", txtFullname.Text); cmd.Parameters.AddWithValue("@UserName", txtUserName.Text); cmd.Parameters.AddWithValue("@Email", txtEmail.Text); cmd.Parameters.AddWithValue("@PhoneNo", txtPhoneno.Text); cmd.Parameters.AddWithValue("@RegionID", DdlRegion.SelectedValue); cmd.Parameters.AddWithValue("@StateId", DdlState.SelectedValue); cmd.Parameters.AddWithValue("@CityID", DdlCity.SelectedValue); cmd.Parameters.AddWithValue("@Password", txtPassword.Text); cmd.Parameters.AddWithValue("@SecurityQue", txtSecurityquestion.Text); cmd.Parameters.AddWithValue("@SecurityAns", txtSecurityanswer.Text); cmd.Parameters.AddWithValue("@MenuMasterID",IsChecked); cmd.ExecuteNonQuery(); con.Close(); } or,try thisforeach (ListItem listItem in chkmenuRights.Items) { if (listItem.Selected == true) { int IsChecked=0; if(chkmenuRights.Checked==True) { IsChecked=1; } SqlConnection con = new SqlConnection(strConnection); con.Open(); cmd = new SqlCommand("Insert Into UserCreation(FullName,UserName,Email,PhoneNo,RegionID,StateId,CityID,Password,SecurityQue,SecurityAns,MenuMasterID) VALUES(@FullName,@UserName,@Email,@PhoneNo,@RegionID,@StateId,@CityID,@Password,@SecurityQue,@SecurityAns,@MenuMasterID)", con); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@FullName", txtFullname.Text); cmd.Parameters.AddWithValue("@UserName", txtUserName.Text); cmd.Parameters.AddWithValue("@Email", txtEmail.Text); cmd.Parameters.AddWithValue("@PhoneNo", txtPhoneno.Text); cmd.Parameters.AddWithValue("@RegionID", DdlRegion.SelectedValue); cmd.Parameters.AddWithValue("@StateId", DdlState.SelectedValue); cmd.Parameters.AddWithValue("@CityID", DdlCity.SelectedValue); cmd.Parameters.AddWithValue("@Password", txtPassword.Text); cmd.Parameters.AddWithValue("@SecurityQue", txtSecurityquestion.Text); cmd.Parameters.AddWithValue("@SecurityAns", txtSecurityanswer.Text); cmd.Parameters.AddWithValue("@MenuMasterID",IsChecked); cmd.ExecuteNonQuery(); con.Close(); }thank u
tdmca
Contributor
2396 Points
661 Posts
Re: how to save checked item into database.
Apr 11, 2012 10:13 AM|LINK
what is menumasterid
sriramabi
Contributor
4351 Points
1277 Posts
Re: how to save checked item into database.
Apr 11, 2012 10:15 AM|LINK
hi
i think MenuMasterID is u r table primary key..So Its automaticaly increase values.so u not assign any values
pls reamove this line u can try
cmd.Parameters.AddWithValue("@MenuMasterID",IsChecked); try thisforeach (ListItem listItem in chkmenuRights.Items) { if (listItem.Selected == true) { SqlConnection con = new SqlConnection(strConnection); con.Open(); cmd = new SqlCommand("Insert Into UserCreation(FullName,UserName,Email,PhoneNo,RegionID,StateId,CityID,Password,SecurityQue,SecurityAns,MenuMasterID) VALUES(@FullName,@UserName,@Email,@PhoneNo,@RegionID,@StateId,@CityID,@Password,@SecurityQue,@SecurityAns,@MenuMasterID)", con); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@FullName", txtFullname.Text); cmd.Parameters.AddWithValue("@UserName", txtUserName.Text); cmd.Parameters.AddWithValue("@Email", txtEmail.Text); cmd.Parameters.AddWithValue("@PhoneNo", txtPhoneno.Text); cmd.Parameters.AddWithValue("@RegionID", DdlRegion.SelectedValue); cmd.Parameters.AddWithValue("@StateId", DdlState.SelectedValue); cmd.Parameters.AddWithValue("@CityID", DdlCity.SelectedValue); cmd.Parameters.AddWithValue("@Password", txtPassword.Text); cmd.Parameters.AddWithValue("@SecurityQue", txtSecurityquestion.Text); cmd.Parameters.AddWithValue("@SecurityAns", txtSecurityanswer.Text); cmd.ExecuteNonQuery(); con.Close(); }
apurva16
Member
21 Points
87 Posts
Re: how to save checked item into database.
Apr 11, 2012 10:27 AM|LINK
hi,
tdmca,i made 2 tables
1)menumaster in this menumasterid,menu caption.in menu caption i stored the all pages for ex.login,ticket status,new ticket etc.
2)menu rights:-in this 3 column made rightsid,userid(foreign),menumasterid(foreign).
and in usercraetion i taked checkbox list and bounded a menucaption.now when i select menurights then it inserted to a table.
in usercreation table i changed mastermenuid to menurightsid.
insert code posted above..
hope u get it.
apurva16
Member
21 Points
87 Posts
Re: how to save checked item into database.
Apr 11, 2012 10:31 AM|LINK
hi sriramabi..
pls see the below post..to get idea about my tables.i want at time of user creation assign the authorization.using this user can see only checked pages..
so i write blow code on create button..
also i am attaching the screen shot of my page to get better idea...
protected void btnCreate_Click(object sender, EventArgs e) { string s = ""; foreach (ListItem listItem in chkMenurights.Items) { if (listItem.Selected == true) { SqlCommand cmd1 = new SqlCommand("insert into MenuUserRights values(@MenuMasterId)"); } } SqlConnection con = new SqlConnection(strConnection); con.Open(); cmd = new SqlCommand("Insert Into UserCreation(FullName,UserName,Email,PhoneNo,RegionID,StateId,CityID,Password,MenuRightsID) VALUES(@FullName,@UserName,@Email,@PhoneNo,@RegionID,@StateId,@CityID,@Password,@MenuRightsID)", con); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@FullName", txtName.Text); cmd.Parameters.AddWithValue("@UserName", txtUsername.Text); cmd.Parameters.AddWithValue("@Email", txtEmail.Text); cmd.Parameters.AddWithValue("@PhoneNo", txtPhone.Text); cmd.Parameters.AddWithValue("@RegionID", ddlRegion.SelectedValue); cmd.Parameters.AddWithValue("@StateId", ddlState.SelectedValue); cmd.Parameters.AddWithValue("@CityID", ddlCity.SelectedValue); cmd.Parameters.AddWithValue("@Password", txtPassword.Text); cmd.Parameters.AddWithValue("@MenuRightsID",chkMenurights.SelectedValue); cmd.ExecuteNonQuery(); con.Close(); ClientScript.RegisterStartupScript(this.GetType(), "Hello", "alert('Successfully created a user');", true); txtName.Text = ""; txtUsername.Text = ""; txtEmail.Text = ""; txtPhone.Text = ""; txtPassword.Text = ""; ddlRegion.SelectedIndex = 0; ddlState.SelectedIndex = 0; ddlCity.SelectedIndex = 0; }if u have team viwer software then tell me i will show online..
apurva16
Member
21 Points
87 Posts
Re: how to save checked item into database.
Apr 11, 2012 10:34 AM|LINK
do you have a team viwer so you can view my problem.i think it is more confusing to tell in words..
Thanx.