title: SQL Insert Query Using C#
body: <p>I'm having an issue at the moment which I am trying to fix. I just tried to access a database and insert some values with the help of C#</p>
  
  <p>The things I tried (worked)</p>
  
  <pre><code>String query = "INSERT INTO dbo.SMS_PW (id,username,password,email) VALUES ('abc',      'abc', 'abc', 'abc')";
  </code></pre>
  
  <p>A new line was inserted and everything worked fine, now I tried to insert a row using variables:</p>
  
  <pre><code>String query = "INSERT INTO dbo.SMS_PW (id,username,password,email) VALUES (@id, @username, @password, @email)";
  
  command.Parameters.AddWithValue("@id","abc")
  command.Parameters.AddWithValue("@username","abc")
  command.Parameters.AddWithValue("@password","abc")
  command.Parameters.AddWithValue("@email","abc")
  
  command.ExecuteNonQuery();
  </code></pre>
  
  <p>Didn't work, no values were inserted. I tried one more thing</p>
  
  <pre><code>command.Parameters.AddWithValue("@id", SqlDbType.NChar);
  command.Parameters["@id"].Value = "abc";
  
  command.Parameters.AddWithValue("@username", SqlDbType.NChar);
  command.Parameters["@username"].Value = "abc";
  
  command.Parameters.AddWithValue("@password", SqlDbType.NChar);
  command.Parameters["@password"].Value = "abc";
  
  command.Parameters.AddWithValue("@email", SqlDbType.NChar);
  command.Parameters["@email"].Value = "abc";
  
  command.ExecuteNonQuery();
  </code></pre>
  
  <p>May anyone tell me what I am doing wrong?</p>
  
  <p>Kind regards</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>in one other line I was creating a new SQL-Command</p>
  
  <pre><code>var cmd = new SqlCommand(query, connection);
  </code></pre>
  
  <p>Still not working and I can't find anything wrong in the code above.</p>