{"id":1249,"date":"2014-05-09T08:06:01","date_gmt":"2014-05-09T08:06:01","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=1249"},"modified":"2022-02-17T07:14:03","modified_gmt":"2022-02-17T07:14:03","slug":"parameters-in-queries","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/sql-server\/queries-microsoft-sql-server\/select-statements\/parameters-in-queries","title":{"rendered":"Parameters In Queries"},"content":{"rendered":"<p>\nA C++ .Net&nbsp;example using parameters\n<\/p>\n<pre><code>\r\n\tSqlCommand1-&gt;CommandType = CommandType::Text;\r\n\tSqlCommand1-&gt;Parameters-&gt;AddWithValue(\"@Type\", Convert::ToString(Type));\r\n\tSqlCommand1-&gt;Parameters-&gt;AddWithValue(\"@LocationId\", Convert::ToString(LocationId));\r\n\tSqlCommand1-&gt;Parameters-&gt;AddWithValue(\"@EventDateTime\", EventDateTime-&gt;ToString(\"s\"));\r\n\tSqlCommand1-&gt;Parameters-&gt;AddWithValue(\"@TagId\", Convert::ToString(TagId));\r\n\tSqlCommand1-&gt;Parameters-&gt;AddWithValue(\"@TagScore\", Convert::ToString(TagScore));\r\n\tSqlCommand1-&gt;Parameters-&gt;AddWithValue(\"@SourceId\", SourceId);\r\n\r\n\tSqlCommand1-&gt;CommandText = \"DELETE FROM tblMyTable WHERE Something = @LocationId\";\r\n\tSqlCommand1-&gt;ExecuteNonQuery();\r\n\r\n\tSqlCommand1-&gt;CommandText = \"INSERT INTO tblMyTable (\t\\\r\n\t\t\t\t\t\t\t   Added,\t\t\t\t\t\\\r\n\t\t\t\t\t\t\t   Type,\t\t\t\t\t\\\r\n\t\t\t\t\t\t\t   LocationId,\t\t\t\t\\\r\n\t\t\t\t\t\t\t   EventDateTime,\t\t\t\\\r\n\t\t\t\t\t\t\t   TagId,\t\t\t\t\t\\\r\n\t\t\t\t\t\t\t   TagScore,\t\t\t\t\\\r\n\t\t\t\t\t\t\t   SourceId\t\t\t\t\t\\\r\n\t\t\t\t\t\t\t   ) VALUES (\t\t\t\t\\\r\n\t\t\t\t\t\t\t   0,\t\t\t\t\t\t\\\r\n\t\t\t\t\t\t\t   @Type,\t\t\t\t\t\\\r\n\t\t\t\t\t\t\t   @LocationId,\t\t\t\t\\\r\n\t\t\t\t\t\t\t   @EventDateTime,\t\t\t\\\r\n\t\t\t\t\t\t\t   @TagId,\t\t\t\t\t\\\r\n\t\t\t\t\t\t\t   @TagScore,\t\t\t\t\\\r\n\t\t\t\t\t\t\t   @SourceId\t\t\t\t\\\r\n\t\t\t\t\t\t\t   )\";\r\n\tSqlCommand1-&gt;ExecuteNonQuery();\r\n<\/code><\/pre>\n<p>\n&nbsp;\n<\/p>\n<p>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A C++ .Net&nbsp;example using parameters SqlCommand1-&gt;CommandType = CommandType::Text; SqlCommand1-&gt;Parameters-&gt;AddWithValue(&#8220;@Type&#8221;, Convert::ToString(Type)); SqlCommand1-&gt;Parameters-&gt;AddWithValue(&#8220;@LocationId&#8221;, Convert::ToString(LocationId)); SqlCommand1-&gt;Parameters-&gt;AddWithValue(&#8220;@EventDateTime&#8221;, EventDateTime-&gt;ToString(&#8220;s&#8221;)); SqlCommand1-&gt;Parameters-&gt;AddWithValue(&#8220;@TagId&#8221;, Convert::ToString(TagId)); SqlCommand1-&gt;Parameters-&gt;AddWithValue(&#8220;@TagScore&#8221;, Convert::ToString(TagScore)); SqlCommand1-&gt;Parameters-&gt;AddWithValue(&#8220;@SourceId&#8221;, SourceId); SqlCommand1-&gt;CommandText = &#8220;DELETE FROM tblMyTable WHERE Something = @LocationId&#8221;; SqlCommand1-&gt;ExecuteNonQuery(); SqlCommand1-&gt;CommandText = &#8220;INSERT INTO tblMyTable ( \\ Added, \\ Type, \\ LocationId, \\ EventDateTime, \\ TagId, \\ TagScore, \\ SourceId \\ ) VALUES ( \\ [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[124,6],"tags":[],"class_list":["post-1249","post","type-post","status-publish","format-standard","hentry","category-queries-microsoft-sql-server","category-select-statements"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1249","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=1249"}],"version-history":[{"count":1,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1249\/revisions"}],"predecessor-version":[{"id":1250,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1249\/revisions\/1250"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=1249"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=1249"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=1249"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}