title: How to insert items into a SQL Server database using reflection?
body: <p>I'm trying to insert some values into the database using reflection. Here is my code, query works well, but how to pass values? I don't know what went wrong:</p>
  <pre><code>public class MyORM&lt;T&gt; where T : IData
  {
      public void Insert(T item)
      {
          var sql = new StringBuilder(&quot;Insert into &quot;);
          var type = item.GetType();
          var properties = type.GetProperties();
  
          sql.Append(type.Name);
          sql.Append(&quot; (&quot;);
  
          foreach (var property in properties)
          {
              sql.Append(property.Name);
              sql.Append(&quot;, &quot;);
          }
  
          sql.Remove(sql.Length - 1, 1);
          sql.Append(&quot;) values (&quot;);
  
          foreach (var property in properties)
          {
              sql.Append('@').Append(property.Name).Append(',');
          }
          sql.Remove(sql.Length - 1, 1);
  
          sql.Append(&quot;);&quot;);
  
          var query = sql.ToString();
  
          var command = new SqlCommand(query, _sqlConnection);
  
          foreach (var property in properties)
          {
              command.Parameters.Add(property.Name);
          }
      }
  }
  </code></pre>