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
7 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Bhuvanesh MohankumarPosted May 19, 2016, 3:47 AM
This is Primary and Foreign Key constraints issue,
Bhuvanesh MohankumarPosted May 19, 2016, 4:16 AM
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.
Thiruppathi RPosted May 19, 2016, 3:47 AM
aditya immadiPosted May 19, 2016, 3:29 AM
Thiruppathi RPosted May 19, 2016, 3:21 AM
aditya immadiPosted May 19, 2016, 2:56 AM
Thiruppathi RPosted May 19, 2016, 2:43 AM