title: VB.Net: SQL check for existing values
body: <p>I have this code asking the user to choose a username:</p>
  
  <pre><code>Dim name As String = InputBox("Input your Username. 15 Characters or Less in Length.", "Choose a Username", "")
  Dim chosenName As String = name.ToUpper
  </code></pre>
  
  <p>This code adds it to my database on phpmyadmin:</p>
  
  <pre><code>Dim SQLStatement As String = "INSERT INTO usernames(username) VALUES('" &amp; chosenName &amp; "')"
  saveUsernames(SQLStatement)
  </code></pre>
  
  <p>Any code to search to check if the username is already taken in the database?</p>
  
  <p>Database structure:
  table name: <code>"usernames"</code></p>
  
  <h2>columbs: <code>"id"</code> and <code>"username"</code></h2>
  
  <p><strong>Please go off of this:</strong></p>
  
  <pre><code>Imports MySql.Data.MySqlClient
  
  Dim serverString As String = "Database=sql477993;Data Source=sql4.freemysqlhosting.net;User Id=sql477993;Password=cF5%gB2*"
  Dim SQLConnection As MySqlConnection = New MySqlConnection
  
  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  SQLConnection.ConnectionString = serverString
  If SQLConnection.State = ConnectionState.Closed Then
  SQLConnection.Open()
  MsgBox("Connected")
  Else
  SQLConnection.Close()
  MsgBox("Closed")
  End If
  End Sub
  
  Public Sub saveUsernames(ByRef SQLStatement As String)
  Dim cmd As MySqlCommand = New MySqlCommand
  With cmd
  .CommandText = SQLStatement
  .CommandType = CommandType.Text
  .Connection = SQLConnection
  .ExecuteNonQuery()
  End With
  SQLConnection.Close()
  MsgBox("Saved")
  SQLConnection.Dispose()
  End Sub
  
  Dim SQLStatement As String = "INSERT INTO usernames(username) VALUES('" &amp; chosenName &amp; "')"
  saveUsernames(SQLStatement)
  </code></pre>