Show SQL from SqlCommandBuilder : SqlCommandBuilder « ADO.Net « C# / CSharp Tutorial






using System;
using System.Data;            
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;

  class Program
  {
    static void Main(string[] args)
    {
      SqlConnection thisConnection = new SqlConnection(
                @"Data Source=.\SQLEXPRESS;" +
                @"AttachDbFilename='NORTHWND.MDF';" +
                @"Integrated Security=True;Connect Timeout=30;User Instance=true");

      thisConnection.Open();

      SqlDataAdapter thisAdapter = new SqlDataAdapter("SELECT CustomerID from Customers", thisConnection);

      SqlCommandBuilder thisBuilder = new SqlCommandBuilder(thisAdapter);
      Console.WriteLine(thisAdapter.SelectCommand.CommandText);

      SqlCommand updateCommand = thisBuilder.GetUpdateCommand();
      Console.WriteLine(updateCommand.CommandText);

      SqlCommand insertCommand = thisBuilder.GetInsertCommand();
      Console.WriteLine(insertCommand.CommandText);

      SqlCommand deleteCommand = thisBuilder.GetDeleteCommand();
      Console.WriteLine(deleteCommand.CommandText);

      thisConnection.Close();
    }
  }








32.23.SqlCommandBuilder
32.23.1.Insert Data using SqlCommandBuilder
32.23.2.Delete Data using CommandBuilder
32.23.3.Show SQL
32.23.4.Show SQL from SqlCommandBuilder