kiran kumar

kiran kumar

  • NA
  • 1k
  • 270.9k

Insert data using parameter in sqlserver

Dec 16 2009 5:38 AM
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e) { MembershipUser newuser = Membership.GetUser(CreateUserWizard1.UserName); Guid newuserid = (Guid)newuser.ProviderUserKey; SqlConnection con = new SqlConnection("Data Source=KIRAN\\SQLEXPRESS;Initial Catalog=kiran;Integrated Security=True"); con.Open(); string querystring; querystring = "insert into reg(username,password,email,securityquestion,securityanswer,userid)values(@username,@password,@email,@securityquestion,@securityanswer,userid)"; SqlCommand cmd = new SqlCommand(querystring, con); SqlParameter uname = new SqlParameter("@UserName", SqlDbType.NVarChar, 50); uname.Value = CreateUserWizard1.UserName; cmd.Parameters.Add(uname); SqlParameter pass = new SqlParameter("@Password", SqlDbType.NVarChar, 50); pass.Value = CreateUserWizard1.Password; cmd.Parameters.Add(pass); SqlParameter ema = new SqlParameter("@Email", SqlDbType.NVarChar, 50); ema.Value = CreateUserWizard1.Email; cmd.Parameters.Add(ema); SqlParameter secques = new SqlParameter("@securityanswer", SqlDbType.NVarChar, 50); secques.Value = CreateUserWizard1.Question; cmd.Parameters.Add(secques); SqlParameter secans = new SqlParameter("@securityquestion", SqlDbType.NVarChar, 50); secans.Value = CreateUserWizard1.Answer; cmd.Parameters.Add(secans); SqlParameter uid= new SqlParameter("@userid", SqlDbType.NVarChar,50); uid.Value = newuserid; cmd.Parameters.Add(uid); cmd.ExecuteNonQuery(); con.Close(); } } } when i run this code it says that"Failed to convert parameter value from a Guid to a String"

Answers (1)