Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Two things. You haven't closed your SQL command:</p> <pre><code>SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Connection"].ConnectionString); SqlCommand cmd = new SqlCommand("Insert into CarTab") </code></pre> <p>And secondly, you don't have any qualifying data to insert in to your CarTab table? You need to specify the fields and values:</p> <pre><code>SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Connection"].ConnectionString); SqlCommand cmd = new SqlCommand("Insert into CarTab(field1, field2) VALUES('val1', 12)") </code></pre> <p>There are a number of other ways to insert data - like the INSERT SELECT:</p> <pre><code>SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Connection"].ConnectionString); SqlCommand cmd = new SqlCommand("Insert into CarTab(field1, field2) SELECT field1, field2 FROM Table2") </code></pre> <p><a href="http://www.sqlteam.com/article/using-select-to-insert-records" rel="nofollow">http://www.sqlteam.com/article/using-select-to-insert-records</a></p> <p>Further to the comments, here is an example of how to fully use ADO in the way you have specified:</p> <pre><code>using System.Data; using System.Data.SqlClient; using (var con = new SqlConnection("your connection string")) { con.Open(); using (var com = con.CreateCommand()) { var var1 = "test"; var var2 = "test2"; com.CommandText = string.Format("INSERT INTO Table1(col1, col2) VALUES({0}, {1})", var1, var2); com.CommandType = CommandType.Text; com.ExecuteNonQuery(); } con.Close(); } </code></pre> <p>Please note that I haven't tested it, but it should give you a good starting block.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload