Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need an <a href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.insertcommand.aspx" rel="noreferrer">InsertCommand</a> in your SqlDataAdapter.</p> <p><strong>EDIT:</strong></p> <p>Here's a quick example I whipped up. There are many others out there, but this should get you going. It assumes that you have a table (dbo.Foos) with two columns (Foo int, Bar nvarchar(50)).</p> <pre><code>namespace DataAdapterSample { using System; using System.Data; using System.Data.SqlClient; class Program { static void Main(string[] args) { using (SqlConnection connection = new SqlConnection(@"Data Source=[your server];Initial Catalog=[your database];Integrated Security=true;")) { using (SqlDataAdapter dataAdapter = new SqlDataAdapter()) { dataAdapter.SelectCommand = new SqlCommand("select Foo, Bar from dbo.Foos", connection); dataAdapter.InsertCommand = new SqlCommand("insert into dbo.Foos (Foo, Bar) values (@Foo, @Bar)", connection); dataAdapter.InsertCommand.Parameters.Add(new SqlParameter("Foo", SqlDbType.Int, 4, "Foo")); dataAdapter.InsertCommand.Parameters.Add(new SqlParameter("Bar", SqlDbType.NText, 50, "Bar")); using (DataSet dataSet = new DataSet()) { dataAdapter.Fill(dataSet); Console.WriteLine("There are {0} rows in the table", dataSet.Tables[0].Rows.Count); DataRow newRow = dataSet.Tables[0].NewRow(); newRow["Foo"] = 5; newRow["Bar"] = "Hello World!"; dataSet.Tables[0].Rows.Add(newRow); dataAdapter.Update(dataSet); } //Just to prove we inserted using (DataSet newDataSet = new DataSet()) { dataAdapter.Fill(newDataSet); Console.WriteLine("There are {0} rows in the table", newDataSet.Tables[0].Rows.Count); } } } Console.ReadLine(); } } } </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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