SqlCommand : executed SQL statement
-
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
-
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
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
-
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
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.
-
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
-
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
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