title: Data Adapter Vs Sql Command
body: <p>Which one would be better in executing an insert statement for ms-sql database:</p>
  
  <blockquote>
    <p>Sql DataAdapter or SQL Command
    Object?</p>
  </blockquote>
  
  <p>Which of them would be better, while <code>inserting only one row</code> and while <code>inserting multiple rows</code>?</p>
  
  <p>A simple example of code usage:</p>
  
  <p><em>SQL Command</em></p>
  
  <pre><code>string query = "insert into Table1(col1,col2,col3) values (@value1,@value2,@value3)";
  int i;
  
  SqlCommand cmd = new SqlCommand(query, connection);
  // add parameters...
  cmd.Parameters.Add("@value1",SqlDbType.VarChar).Value=txtBox1.Text;
  cmd.Parameters.Add("@value2",SqlDbType.VarChar).Value=txtBox2.Text;
  cmd.Parameters.Add("@value3",SqlDbType.VarChar).Value=txtBox3.Text;
  cmd.con.open();
  i = cmd.ExecuteNonQuery();
  cmd.con.close();
  </code></pre>
  
  <p><em>SQL Data Adapter</em></p>
  
  <pre><code>DataRow dr = dsTab.Tables["Table1"].NewRow();
  DataSet dsTab = new DataSet("Table1");
  SqlDataAdapter adp = new SqlDataAdapter("Select * from Table1", connection);
  adp.Fill(dsTab, "Table1");
  dr["col1"] = txtBox1.Text;
  dr["col2"] = txtBox5.Text;    
  dr["col3"] = "text";
  
  dsTab.Tables["Table1"].Rows.Add(dr);
  
  SqlCommandBuilder projectBuilder = new SqlCommandBuilder(adp);
  DataSet newSet = dsTab.GetChanges(DataRowState.Added);
  adp.Update(newSet, "Table1");
  </code></pre>