{"id":117,"date":"2016-02-17T16:37:01","date_gmt":"2016-02-17T16:37:01","guid":{"rendered":"https:\/\/ibex.tech\/csharp\/?p=117"},"modified":"2022-02-17T06:24:15","modified_gmt":"2022-02-17T06:24:15","slug":"select-queries","status":"publish","type":"post","link":"https:\/\/ibex.tech\/csharp\/c-sharp\/databases\/sqlite\/queries\/select\/select-queries","title":{"rendered":"SELECT Queries"},"content":{"rendered":"<h4>\n\tSELECT Query Example<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\tCommand1 = new System.Data.SQLite.SQLiteCommand(Connection1);\r\n\tCommand1.CommandText = &quot;SELECT * FROM MyTable WHERE SomeColumnName &gt;= @StartValue AND SomeColumnName &lt;= @EndValue&quot;;\r\n\tCommand1.Parameters.AddWithValue(&quot;@StartValue&quot;, 14);\r\n\tCommand1.Parameters.AddWithValue(&quot;@EndValue&quot;, 28);\r\n\r\n\tSystem.Data.SQLite.SQLiteDataReader Reader1 = Command1.ExecuteReader();\r\n\t{\r\n\t\twhile (Reader1.Read())\r\n\t\t{\r\n\t\t\t\/\/MyVariable = Convert.ToString(Reader1[\"SomeColumnName1\"]);\r\n\t\t\t\/\/MyVariable2 = Convert.ToInt32(Reader1[\"SomeColumnName2\"]);\r\n\t\t}\r\n\t}\r\n\tReader1.Close();\r\n<\/code><\/pre>\n<h4>\n\tGetting Count Of Rows Returned<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\t\/\/Get the number of results that will be returned\r\n\tint RowCount = 0;\r\n\tCommand1 = new System.Data.SQLite.SQLiteCommand(Connection1);\r\n\tCommand1.CommandText = &quot;SELECT count(*) FROM MyTable WHERE SomeColumnName &gt;= @StartValue AND SomeColumnName &lt;= @EndValue&quot;;\t\t\/\/The count() will return the number of results\r\n\tRowCount = Convert.ToInt32(Command1.ExecuteScalar());\r\n\t\r\n\t\/\/Get the results\r\n\tCommand1.CommandText = &quot;SELECT * FROM MyTable WHERE SomeColumnName &gt;= @StartValue AND SomeColumnName &lt;= @EndValue&quot;;\r\n\tCommand1.Parameters.AddWithValue(&quot;@StartValue&quot;, 14);\r\n\tCommand1.Parameters.AddWithValue(&quot;@EndValue&quot;, 28);\r\n\r\n\tSystem.Data.SQLite.SQLiteDataReader Reader1 = Command1.ExecuteReader();\r\n\t{\r\n\t\twhile (Reader1.Read())\r\n\t\t{\r\n\t\t\t\/\/MyVariable = Convert.ToString(Reader1[\"SomeColumnName1\"]);\r\n\t\t\t\/\/MyVariable2 = Convert.ToInt32(Reader1[\"SomeColumnName2\"]);\r\n\t\t}\r\n\t}\r\n\tReader1.Close();\r\n<\/code><\/pre>\n<h4>\n\tReading DateTime&nbsp;In Select Statements<br \/>\n<\/h4>\n<p>\n\tYou need to specify you want the value returning in a DateTime format or you can just get the year portion returned!\n<\/p>\n<pre>\r\n<code>\r\n\tCommand1.CommandText = &quot;SELECT datetime(LogDateTime) as LogDateTime, SomeOtherColumnName FROM MyTable&quot;;\r\n<\/code><\/pre>\n<p>\n\t&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SELECT Query Example Command1 = new System.Data.SQLite.SQLiteCommand(Connection1); Command1.CommandText = &quot;SELECT * FROM MyTable WHERE SomeColumnName &gt;= @StartValue AND SomeColumnName &lt;= @EndValue&quot;; Command1.Parameters.AddWithValue(&quot;@StartValue&quot;, 14); Command1.Parameters.AddWithValue(&quot;@EndValue&quot;, 28); System.Data.SQLite.SQLiteDataReader Reader1 = Command1.ExecuteReader(); { while (Reader1.Read()) { \/\/MyVariable = Convert.ToString(Reader1[&#8220;SomeColumnName1&#8221;]); \/\/MyVariable2 = Convert.ToInt32(Reader1[&#8220;SomeColumnName2&#8221;]); } } Reader1.Close(); Getting Count Of Rows Returned \/\/Get the number of results that will be [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-117","post","type-post","status-publish","format-standard","hentry","category-select"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/117","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/comments?post=117"}],"version-history":[{"count":2,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/117\/revisions"}],"predecessor-version":[{"id":124,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/117\/revisions\/124"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/media?parent=117"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/categories?post=117"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/tags?post=117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}