Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7961759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:08:23+00:00 2026-06-04T05:08:23+00:00

First tread on stack overflow, i will try to do my best.. Below, my

  • 0

First tread on stack overflow, i will try to do my best..

Below, my model from ADO.NET (mysql database)

http://img585.imageshack.us/img585/4533/screenshot20120519at143.png

// CHECK USER+PASS
rmEntities2 myDb = new rmEntities2();
var query = from c in myDb.users
            where c.use_login == run.name
            where c.use_password == run.pass
            select c.use_id;

if (query.Count() == 0)
{
    return "ERROR USER/PASSWORD";
}
else
{
    // Linq insert DB
    running newRun = new running();
    newRun.run_start_time = new System.DateTime(1970, 1, 1, 0, 0, 0, 0)
        .AddSeconds(Double.Parse(run.start));
    newRun.run_end_time = new System.DateTime(1970, 1, 1, 0, 0, 0, 0)
        .AddSeconds(Double.Parse(run.stop));
    newRun.run_distance = (float)run.distance;
    newRun.run_nbfootsteps = run.nbfootsteps;
    newRun.run_vo2max = run.vo2Max;

    foreach (int u in query)
    {
        newRun.user.use_id = u;
    }

    myDb.AddTorunnings(newRun);
    myDb.SaveChanges();
    return "RUNNING ADDED";
}

The problem is from this line :

newRun.user.use_id = u;

I would like set up the run_use_id from user in my running table.

What is the best way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T05:08:25+00:00Added an answer on June 4, 2026 at 5:08 am

    I expect that when you try to set the use_id value in the line

    newRun.user.use_id = u;
    

    you’re getting a NullReferenceException. This is because newRun.user is null – the new run is not associated with a user.

    I’d suggest that instead of working with the use_id, instead work with the user.

    var query = from c in myDb.users
                where c.use_login == run.name
                where c.use_password == run.pass
                select c;
    var user = query.SingleOrDefault();
    

    and then either of these:

    newRun.user = user; 
    // or 
    user.runnings.Add(newRun);
    

    They both do the same thing, but use whichever makes more sense to you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

first, please see the blog as the link showed below: http://blogs.nitobi.com/joe/2008/10/17/phonegap-now-for-android/comment-page-1/#comment-12918 the author made
this is my first post on stack overflow! I'm new to Java and I've
Helloes good people of Stack Overflow, I have a .NET client-server application running with
My first post to Stack Overflow so be gentle please! I am about to
This is the first time i'm asking a question here at stack overflow so
first post ever on stack overflow! Anyway...I'm trying to teach myself networking programming in
I'm very new to jQuery and this is my first post to Stack Overflow.
I try to learn writing parallel codes with thread library of c++11 so first
First of all, I'm really new to the MVC Asp.Net ideology. I would like
I have some jsp pages that connect to a mysql database and I intermittently

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.