Inserting Data Using SQLStatements : SqlCommand Insert « ADO.Net « C# / CSharp Tutorial






using System;
using System.Data;
using System.Data.SqlClient;

class MainClass
{
  static void Main(string[] args)
  {
    SqlConnection MyConnection = new SqlConnection("server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI;");

    MyConnection.Open();

    String MyString = @"INSERT INTO Employee(ID, FirstName, LastName) VALUES(2, 'G', 'M')";
    SqlCommand MyCmd = new SqlCommand(MyString, MyConnection);

    MyCmd.ExecuteScalar();
    MyConnection.Close();
  }
}








32.20.SqlCommand Insert
32.20.1.Inserting Data Using SQLStatements
32.20.2.Execute nonquery to insert a record (row)
32.20.3.how to execute multiple SQL statements using a SqlCommand object
32.20.4.Command NonQuery