Base solution for your next web application
Open Closed

How to store data in two different table #324


User avatar
0
abu created

how we store data in two different table with one table primary key set as foreign key on second table with one method call.

public void CreateUser(CreateUserInput input)
        {
          
            var userinfo = new User
            {
                EmailID = input.EmailID,
                Password = input.Password,
                DateTimeLastUpdated = DateTime.Now,
                DateTimeLastLogin = DateTime.Now,
                IsActive = 0,
                IsVerified = 0
            };

            userinfo.Id = _userRepository.InsertOrUpdateAndGetId(userinfo);
            uid = userinfo.Id;
            try
            {
                if (uid!= 0)
                {
                    var companyinfo = new CompanyProfile
                    {
                        UserId = uid,
                        CompanyName = input.CompanyName
                    };
                    _companyprofileRepository.Insert(companyinfo);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

getting internal error in this part


3 Answer(s)
  • User Avatar
    0
    theedge created

    Can you include the exception message you are getting as well as the stack trace?

  • User Avatar
    0
    hikalkan created
    Support Team

    Your code seems correct. You should share exception details here. You can find it in logs.

  • User Avatar
    0
    abu created

    sir this problem is resolved because there is such fields in the table which is not null and i am not inserting data.. thank you sir for your reply