title: c# last insert id using table adapter
body: <p>I'm trying to get the last inserted id out of the database. I've tried many different code snippets but still having no luck. Here's the code I'm using for the inserts. I need the last insert id from the first to insert as nId in the second. I've tried SELECT @@IDENTITY but null value errors appeared which I couldn't locate. Can anybody show me the correct code please?</p>
  
  <pre><code>// Insert new user
  daUsers.Insert(textBoxUsername.Text, textBoxPassword.Text);
  
  // Insert new Twitter OAuth
  daTwitterOAuth.Insert(nId, textBoxConsumerKey.Text, textBoxConsumerSecret.Text, textBoxToken.Text, textBoxTokenSecret.Text);
  </code></pre>