title: Select Statement SQL in VB
body: <p>I understand that there are other posts such as this, however I cannot find one that will work for me and Im really at the end of my tether with this, I really dont know what to do. </p>
  
  <p>I have a few tables with ID columns and name columns, that are connected by Link Tables through foreign keys etc. I'm trying to enter data into the database via a GUI and to do so I'm using insert statements into the 'regular' tables, then Select statements to get the autogen IDs from the regular table to then insert into the link tables.</p>
  
  <p>The code below is what I've been trying to use to do this.</p>
  
  <pre><code>Imports System.Data.SqlClient
      Public Class Test
  
  Private cs As New SqlConnection(".....")
  
  Private Sub btnInsertNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsertNext.Click
          Dim ContID As Integer
          Dim FName As Integer
  
  
          cs.Open()
  
  Using command As New SqlCommand("Select FamID From Family Where Name = '" &amp; FName &amp; " '", cs)
              command.Parameters.AddWithValue("@FamID", ContID)
              command.ExecuteNonQuery()
          End Using
  
    Using command As New SqlCommand("Select DocID From Doctors Where DocName LIKE'" &amp; AddFam.Doctor &amp; " '", cs)
              command.Parameters.AddWithValue("@DocID", AddFam.Doctor) ''AddFam is another form I'm using to add a family member to a Doctor
              command.ExecuteNonQuery()
          End Using
  
  cs.close()
  </code></pre>
  
  <p>I'm using:
  VB 2010
  SQL server management 2008 r2</p>
  
  <p>I understand its a bit muddley but any help would be greatly appreciated, and I'm sorry if this has come up before. </p>