Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. SqlCommand : executed SQL statement

SqlCommand : executed SQL statement

Scheduled Pinned Locked Moved C#
databasequestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dlarkin77
    wrote on last edited by
    #1

    Hi, Suppose I have a SqlCommand as follows:

    SqlCommand cmd = new SqlCommand();
    cmd.Connection = ;
    cmd.CommandText = "Insert Into MyTable (Name, Surname) Values (@Name, @Value)";
    cmd.Parameters.AddWithValue("@Name", "David");
    cmd.Parameters.AddWithValue("@Surname", "Larkin");
    cmd.ExecuteNonQuery();

    This will end up with the following SQL being executed : "Insert Into MyTable (Name, Surname) Values ('David', 'Larkin')" Is there any way to actually see the SQL that gets executed? Something like cmd.ExecutedStatement or similar? Thanks, dlarkin77

    G P D W 4 Replies Last reply
    0
    • D dlarkin77

      Hi, Suppose I have a SqlCommand as follows:

      SqlCommand cmd = new SqlCommand();
      cmd.Connection = ;
      cmd.CommandText = "Insert Into MyTable (Name, Surname) Values (@Name, @Value)";
      cmd.Parameters.AddWithValue("@Name", "David");
      cmd.Parameters.AddWithValue("@Surname", "Larkin");
      cmd.ExecuteNonQuery();

      This will end up with the following SQL being executed : "Insert Into MyTable (Name, Surname) Values ('David', 'Larkin')" Is there any way to actually see the SQL that gets executed? Something like cmd.ExecutedStatement or similar? Thanks, dlarkin77

      G Offline
      G Offline
      Giorgi Dalakishvili
      wrote on last edited by
      #2

      You can use sql server profiler to see actual query. I'm not aware of other ways to see it.

      Giorgi Dalakishvili #region signature my articles #endregion

      1 Reply Last reply
      0
      • D dlarkin77

        Hi, Suppose I have a SqlCommand as follows:

        SqlCommand cmd = new SqlCommand();
        cmd.Connection = ;
        cmd.CommandText = "Insert Into MyTable (Name, Surname) Values (@Name, @Value)";
        cmd.Parameters.AddWithValue("@Name", "David");
        cmd.Parameters.AddWithValue("@Surname", "Larkin");
        cmd.ExecuteNonQuery();

        This will end up with the following SQL being executed : "Insert Into MyTable (Name, Surname) Values ('David', 'Larkin')" Is there any way to actually see the SQL that gets executed? Something like cmd.ExecutedStatement or similar? Thanks, dlarkin77

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #3

        You have to look at the database to see what's going on. The Performance Analyzer will tell you what's going on because you can use it to watch the activity on the database.

        Deja View - the feeling that you've seen this post before.

        My blog | My articles

        1 Reply Last reply
        0
        • D dlarkin77

          Hi, Suppose I have a SqlCommand as follows:

          SqlCommand cmd = new SqlCommand();
          cmd.Connection = ;
          cmd.CommandText = "Insert Into MyTable (Name, Surname) Values (@Name, @Value)";
          cmd.Parameters.AddWithValue("@Name", "David");
          cmd.Parameters.AddWithValue("@Surname", "Larkin");
          cmd.ExecuteNonQuery();

          This will end up with the following SQL being executed : "Insert Into MyTable (Name, Surname) Values ('David', 'Larkin')" Is there any way to actually see the SQL that gets executed? Something like cmd.ExecutedStatement or similar? Thanks, dlarkin77

          D Offline
          D Offline
          dlarkin77
          wrote on last edited by
          #4

          I'll look into SQL Server Profiler and the Performance Analyzer. Thanks very much, dlarkin77

          1 Reply Last reply
          0
          • D dlarkin77

            Hi, Suppose I have a SqlCommand as follows:

            SqlCommand cmd = new SqlCommand();
            cmd.Connection = ;
            cmd.CommandText = "Insert Into MyTable (Name, Surname) Values (@Name, @Value)";
            cmd.Parameters.AddWithValue("@Name", "David");
            cmd.Parameters.AddWithValue("@Surname", "Larkin");
            cmd.ExecuteNonQuery();

            This will end up with the following SQL being executed : "Insert Into MyTable (Name, Surname) Values ('David', 'Larkin')" Is there any way to actually see the SQL that gets executed? Something like cmd.ExecutedStatement or similar? Thanks, dlarkin77

            W Offline
            W Offline
            Wendelius
            wrote on last edited by
            #5

            Profiler gives the exact info from database side (however parameters may cause a little headache at certain situations). As an alternative approach you could take a look at this. Although it's for OleDb, the idea is the same for SqlCommand(personally I usetecnique similar to this against Oracle). http://www.codeproject.com/script/Forums/View.aspx?fid=1725&fr=151&select=2709230#xx2709230xx[^] Mika

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups