title: VB.Net and MySQL
body: <p>I am using VB.Net and MySQL as it's database, I'm a newbie. I have a problem using Foreign key in MySQL. In MySQL, I've created <code>inq</code> Table as its primary table and <code>inqcontact</code> Table. Here's my MySQL code:</p>
  
  <pre><code>CREATE TABLE inq(
       number INT NOT NULL AUTO_INCREMENT,
       lastname VARCHAR(20),
       firstname VARCHAR(20),
       middlename VARCHAR(20),
       PRIMARY KEY(number));
  
  CREATE TABLE inqcontact(
       noinqcontact INT NOT NULL AUTO_INCREMENT,
       mobile VARCHAR(20),
       telephone VARCHAR(20),
       emailadd VARCHAR(20),
       number INT,
       PRIMARY KEY(noinqcontact),
       FOREIGN KEY(number) REFERENCES inq(number));
  </code></pre>
  
  <p>and here's my VB.Net code:</p>
  
  <pre><code>CommInq1 = New MySqlCommand("INSERT INTO inq VALUES (number,'" &amp; txtLastName.Text &amp; "','" &amp; txtFirstName.Text &amp; "','" &amp; txtMiddleName.Text &amp; "')", ConnInq)
          ConnInq.Open()
          CommInq1.ExecuteNonQuery()
  
          CommInq2 = New MySqlCommand("INSERT INTO inqcontact VALUES (noinqcontact,'" &amp; txtMobileNo.Text &amp; "','" &amp; txtTelephoneNo.Text &amp; "','" &amp; txtEmailAdd.Text &amp; "',number )", ConnInq)
          CommInq2.ExecuteNonQuery()
          ConnInq.Close()
  
          MessageBox.Show("Saved!", "")
  </code></pre>
  
  <p>My VB.Net code returns NULL value to the <code>number</code> Foreign Key in <code>inqcontact</code> Table. I mean, in <code>inq</code> Table, the <code>number</code> field automatically increments itself so there's no problem with it. But in <code>inqcontact</code> Table, the <code>number</code> Field, which is the Foreign Key, is NULL value. Could you tell me what's wrong with the code I've provided? I think, the error is in the insertion of data from my VB.Net. </p>