Hai all i wrote this lines for creating password after registration page here id in Tb_User is primarykey and UserIDFromRegistration column is foriegnkey in tb_login
my contoller is
public ActionResult CreatePassword(Tbl_LoginCredentials user)
{
int userid = 0;
string name = null, Email = null;
name = Session["name"].ToString();
Email = Session["Email"].ToString();
int i = v.CreatePassword( user.Password, name, Email);
return view();
}
public int CreatePassword( string password, string name, string Email)
{
int i = 0;
SqlConnection con = new SqlConnection(s);
SqlCommand cmd = new SqlCommand("Sp_CreatePassword",con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@Password", SqlDbType.NVarChar)).Value = password;
cmd.Parameters.Add(new SqlParameter("@UserName", SqlDbType.NVarChar)).Value = name;
cmd.Parameters.Add(new SqlParameter("@Email", SqlDbType.NVarChar)).Value = Email;
con.Open();
i=cmd.ExecuteNonQuery();
con.Close();
return i;
i bring email and name from sessions and in case of id i think primarykey relation may work but it says
Cannot insert the value NULL into column 'UserIDFromRegistration', table 'JT.dbo.Tbl_LoginCredentials'; column does not allow nulls. INSERT fails.
and my stored proc is
ALTER Proc [dbo].[Sp_CreatePassword]
(
@Password nvarchar(50),
@UserName nvarchar(50),
@Email nvarchar(50)
)
as
begin
insert into Tbl_LoginCredentials (Password,UserName,Email) values (@Password ,@UserName ,@Email)
end
please help me...i struck in this for 2 days
TIA

Bhuvanesh MohankumarRank #310 · 8.1K reputationPosted May 18, 2016, 11:47 PM EDT
This is Primary and Foreign Key constraints issue,
Thiruppathi RRank #404 · 6.2K reputationPosted May 18, 2016, 10:43 PM EDT
aditya immadi144 reputationPosted May 18, 2016, 10:56 PM EDT
Thiruppathi RRank #404 · 6.2K reputationPosted May 18, 2016, 11:21 PM EDT
aditya immadi144 reputationPosted May 18, 2016, 11:29 PM EDT
Thiruppathi RRank #404 · 6.2K reputationPosted May 18, 2016, 11:47 PM EDT
Bhuvanesh MohankumarRank #310 · 8.1K reputationPosted May 19, 2016, 12:16 AM EDT
Tryinserting the "0" values forthat ID reference and executean let me know.
If "Empty", you can understand no data has been created related to that, if "0" then you can understand some value has been inserted in other table which you have to update with proper values.