{"id":1444,"date":"2022-10-10T18:12:25","date_gmt":"2022-10-11T00:12:25","guid":{"rendered":"https:\/\/www.great-white-software.com\/blog\/?p=1444"},"modified":"2022-10-10T18:14:43","modified_gmt":"2022-10-11T00:14:43","slug":"working-with-databases-in-c","status":"publish","type":"post","link":"https:\/\/www.great-white-software.com\/blog\/2022\/10\/10\/working-with-databases-in-c\/","title":{"rendered":"Working with databases in C#"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The trek continues !<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One of the common things we need our applications to do is interact with a database. Sometimes its just a local SQLite, or other stand alone db engine like that, or some &#8220;Big Iron&#8221; database like Oracle, MS SQL Server, PostgreSQL, etc. Or maybe a NoSQL database like Mongo ?<br>With Xojo there are only a handful of plugins Tod ell with the vast majority of databases. Either you use the ones provided by Xojo. Or the ones from MBS or Valentina, or CubeSQL. There just arent that many vendors or plugins to have to wade through<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In C#, because its widely available on so many platforms, there are tons of NuGet packages to select from. I cant tell you all of them or which specific ones will \/ wont work on macOS. I haven&#8217;t tried them all \ud83d\ude42<br>Typing in &#8220;database&#8221; to the search field in the package manager gives a scrolling list that is immense.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"525\" height=\"423\" src=\"https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-4.10.13-PM.png?resize=525%2C423&#038;ssl=1\" alt=\"\" class=\"wp-image-1445\" srcset=\"https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-4.10.13-PM.png?resize=1024%2C826&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-4.10.13-PM.png?resize=300%2C242&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-4.10.13-PM.png?resize=768%2C620&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-4.10.13-PM.png?w=1340&amp;ssl=1 1340w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"525\" height=\"350\" src=\"https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-4.11.41-PM.png?resize=525%2C350&#038;ssl=1\" alt=\"\" class=\"wp-image-1446\" srcset=\"https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-4.11.41-PM.png?resize=1024%2C683&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-4.11.41-PM.png?resize=300%2C200&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-4.11.41-PM.png?resize=768%2C512&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-4.11.41-PM.png?w=1366&amp;ssl=1 1366w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">325,832 packages is much like saying &#8220;there are 325,832 plugins for Xojo&#8221;<br>Christians good but I dont think even he&#8217;s got that many \ud83d\ude1b<br><br>So there is a LOT to choose from and databases are no exception. This chapter isn&#8217;t a &#8220;how to do anything with any database in C#&#8221; but how to use one specific NuGet package to use SQLITE. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So lets get started !<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I&#8217;m still adding to my standard &#8220;Getting Started project&#8221;<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"525\" height=\"338\" src=\"https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-4.15.48-PM.png?resize=525%2C338&#038;ssl=1\" alt=\"\" class=\"wp-image-1447\" srcset=\"https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-4.15.48-PM.png?resize=1024%2C659&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-4.15.48-PM.png?resize=300%2C193&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-4.15.48-PM.png?resize=768%2C494&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-4.15.48-PM.png?w=1529&amp;ssl=1 1529w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In order to &#8220;add a plugin&#8221; in Xojo you&#8217;d add it to the IDE&#8217;s Plugins, restart and it would be available in every project you opened. VS works differently and each solution can have a different list of packages and even different versions of the same package.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For our purpose we&#8217;re going to add a <em>reference<\/em> to our project to make this package usable in our code.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"525\" height=\"336\" src=\"https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-4.18.03-PM.png?resize=525%2C336&#038;ssl=1\" alt=\"\" class=\"wp-image-1448\" srcset=\"https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-4.18.03-PM.png?resize=1024%2C655&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-4.18.03-PM.png?resize=300%2C192&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-4.18.03-PM.png?resize=768%2C491&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-4.18.03-PM.png?w=1533&amp;ssl=1 1533w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Select the <em>references<\/em> item and right click (or you can just select the <em>Project<\/em> > <em>Add Reference&#8230;<\/em> menu item)<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"525\" height=\"335\" src=\"https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-4.18.26-PM.png?resize=525%2C335&#038;ssl=1\" alt=\"\" class=\"wp-image-1449\" srcset=\"https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-4.18.26-PM.png?resize=1024%2C654&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-4.18.26-PM.png?resize=300%2C192&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-4.18.26-PM.png?resize=768%2C491&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-4.18.26-PM.png?w=1536&amp;ssl=1 1536w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">For THIS project we&#8217;re going to add <strong>Mono.Data.SQLite<\/strong> and <strong>System.Data<\/strong><br>Check the check box next to them and they&#8217;ll be added to the list on the right<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"525\" height=\"349\" src=\"https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-4.23.10-PM.png?resize=525%2C349&#038;ssl=1\" alt=\"\" class=\"wp-image-1450\" srcset=\"https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-4.23.10-PM.png?w=1020&amp;ssl=1 1020w, https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-4.23.10-PM.png?resize=300%2C199&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-4.23.10-PM.png?resize=768%2C510&amp;ssl=1 768w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Press select &amp; they&#8217;ll be added to your project.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"372\" height=\"540\" src=\"https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-4.25.04-PM.png?resize=372%2C540&#038;ssl=1\" alt=\"\" class=\"wp-image-1451\" srcset=\"https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-4.25.04-PM.png?w=372&amp;ssl=1 372w, https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-4.25.04-PM.png?resize=207%2C300&amp;ssl=1 207w\" sizes=\"auto, (max-width: 372px) 100vw, 372px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Our app doesnt have a lot of code in it &#8211; yet &#8211; so tying a database into it is a little contrived.<br>All we have is a window that we have textfields on and it just has a got focus event.<br>Lets add a listbox to the window so we can put some data into something familiar.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>list = new ListBox( (float)textfield2.Left,\n                    (float)(textfield2.Top + textfield2.Height + 12),\n                    (float)(kDefaultWidth - 20),\n                    (float)(kDefaultHeight - (textfield2.Top + \n                              textfield2.Height + 12 + 12)) );\n            list.LockLeft = true;\n            list.LockTop = true;\n            list.LockRight = true;\n            list.LockBottom = true;\n\nreturn new Control&#91;] { textfield1, textfield2, list };\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">I defined 2 constants for the default height and width of the window so I could reuse those elsewhere. And yes, control locking works just like in Xojo \ud83d\ude42<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\nnamespace getting_started\n{\n\tpublic class MainWindow : Window\n\t{\n\n        const int kDefaultWidth = 600;\n        const int kDefaultHeight = 400;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">And I altered my SetUpWindow method to use those constants instead of the hard coded literals.<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">What you should notice is how C# does a CAST &#8211; in Xojo its like<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>INTEGER( expression you want treated as an integer )\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">almost like a function call. In C# its <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>(INTEGER) expression you want treated as an integer \n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">so you have to be sure to put brackets around the expression you want to cast. Often I just write<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>(INTEGER)( expression you want treated as an integer )<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">just to be safe. BU the &#8220;style gods&#8221; and language pedants get upset at this verbosity \ud83d\ude42<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">OK so now we have a list to show data in. We could load the data in the control creation method but we&#8217;ll add it elsewhere since thats more like what we would do in many cases. I&#8217;m going to add a button next to the lower text field, just because that seems a good place, and then hook the database code into the pushbutton push event. I added a declaration of the button with the listbox and other controls :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>        Button pushButton;\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">and added this code to the method creating all the controls<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pushButton = new Button((float)(textfield2.Left + textfield2.Width + 12),\n                        (float)(textfield2.Top),\n                        80,\n                        22);\n\npushButton.Pressed += pushbutton_Pressed;\n\nreturn new Control&#91;] { textfield1, textfield2, list, pushButton };\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For right now the method for pushbutton_Pressed looks like<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>private void pushbutton_Pressed(object sender, EventArgs e)\n{\n            \n\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You should still be able to run &amp; the button will just do nothing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To use Sqlite in this code we will need to add a <em>using<\/em> statement.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using Mono.Data.Sqlite;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Typically these are all at the top of whatever source code file you&#8217;re working in. I like to group them <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"400\" height=\"204\" src=\"https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-5.34.52-PM.png?resize=400%2C204&#038;ssl=1\" alt=\"\" class=\"wp-image-1452\" srcset=\"https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-5.34.52-PM.png?w=400&amp;ssl=1 400w, https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2022\/10\/Screen-Shot-2022-10-10-at-5.34.52-PM.png?resize=300%2C153&amp;ssl=1 300w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The Sqlite package we added uses a form of access to the DB that is very similar to what Xojo has, but its not identical.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The code we&#8217;re going to add will use local variables, but moving those to be application or window wide is a trivial operation so it really won&#8217;t matter much.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First we need to declare a variable to hold the <em>Sqlite_connection<\/em> &#8211; this would be analogous to defining a variable for the SQLiteDatabase object in Xojo.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Mono.Data.Sqlite.SqliteConnection sqlite_conn; \n\/\/ in Xojo var sqlite_conn as SQLiteDatabase\n   <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then we need to create the instance &#8211; this will attach to an in memory database. In Xojo this is different &#8211; we just dont open a database file<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> sqlite_conn = new SqliteConnection(\"Data Source=:memory:\");\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then we actually tell this new connection to OPEN and attach to whatever database we set up as the data source<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sqlite_conn.Open();<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">About this point you&#8217;re wondering <em>Great but how do I check errors ?<\/em> This is one are where .Net and Xojo, now, agree. .Net uses EXCEPTIONS for error handling ( at least with this database although I expect others are similar)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So in reality our code should look like<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Mono.Data.Sqlite.SqliteConnection sqlite_conn;\n\ntry\n{\n    sqlite_conn = new SqliteConnection(\"Data Source=:memory:\");\n\n    sqlite_conn.Open();\n }\n catch (Mono.Data.Sqlite.SqliteException exc)\n {\n   Console.WriteLine(\"An error occurred {0}\", exc.Message);\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">All the rest of the code we&#8217;ll add will be inside the TRY CATCH block following the opening of the connection.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The API that .Net uses for many database is ADO. Its a lot like what Xojo uses but has syntax differences. See https:\/\/learn.microsoft.com\/en-us\/sql\/ado\/guide\/ado-programmer-s-guide?view=sql-server-ver16<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">About the biggest difference is that ADO seems a tad more low level. In some ways that makes certain thinks possible and in other ways it&#8217;s a pain because it means you write more code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Onwards !<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In order to RUN any sql command we need a <em>command object<\/em> &#8211; an <em>IDbCommand<\/em>. Then we configure that object and then tell it to execute. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>IDbCommand dbcmd = sqlite_conn.CreateCommand();\nstring sql = \"create table employee ( firstname, lastname )\";\ndbcmd.CommandText = sql;\ndbcmd.ExecuteNonQuery();<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Just as in Xojo there are several ways to execute sql statements &#8211; some that return results, some that return a single result, or ones that return no results at all.  The previous code returns no results hence its a &#8220;non-query&#8221;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And since this is an in memory database we&#8217;ll just add a few rows to it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sql = \"insert into employee ( firstname, lastname ) values('Norm', 'Palardy')\";\ndbcmd.CommandText = sql;\ndbcmd.ExecuteNonQuery();\n\nsql = \"insert into employee ( firstname, lastname ) values('Joe', 'Smith')\";\ndbcmd.CommandText = sql;\ndbcmd.ExecuteNonQuery();<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now we have a database connection, a table, and some data in it. To read that data we&#8217;ll need the ADO equivalent of a Xojo <em>recordset<\/em> or <em>rowset<\/em>. This is an <em>IDataReader<\/em>. Also since the command were going to execute will return a reader well just a different method &#8211; just like in Xojo where you&#8217;d use <em>SQLSelect<\/em> or <em>SelectSQL<\/em>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sql = \"SELECT firstname, lastname FROM employee\";\ndbcmd.CommandText = sql;\nIDataReader reader = dbcmd.ExecuteReader();\n\nwhile (reader.Read())\n{\n     string firstName = reader.GetString(0);\n     string lastName = reader.GetString(1);\n     list.AddRow(firstName + \" \" + lastName);\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">One thing to notice is that unlike Xojo&#8217;s rowset and recordset YOU dont have to remember to say &#8220;move to the next row&#8221; &#8211; and if you&#8217;ve ever forgotten that and wondered why your application runs into an infinite loop you&#8217;ll appreciate this.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Reader.Read not only moves to the next row of the returned rows it also returns a boolean value when it succeeds. This way you can move to the next row without having to write any code. Make sure you check out ALL the possible GetXXXXX methods that the reader has &#8211; they are extensive. In our simplfusage above we just retrieve, by column position, the strings returned and add that as a single row to the listbox.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As a good citizen we should ALWAYS dispose of the objects we created.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  \/\/ clean up\nreader.Dispose();\ndbcmd.Dispose();\nsqlite_conn.Close();<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">And &#8211; were done !<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Note there are things I have not covered <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>creating a new database <\/li><li>configuring the connection to read from an existing db file (see <strong>For the 2.0 profile in the new assembly<\/strong> on https:\/\/www.mono-project.com\/docs\/database-access\/providers\/sqlite\/)<\/li><li>using prepared statements (which also exist)<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">I&#8217;m sure there are many other things<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And as <a href=\"https:\/\/great-white-software.com\/miscellaneous\/CSharp\/getting_started-2022-10-10.zip\">always a link to the project so far<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The trek continues ! One of the common things we need our applications to do is interact with a database. Sometimes its just a local SQLite, or other stand alone db engine like that, or some &#8220;Big Iron&#8221; database like Oracle, MS SQL Server, PostgreSQL, etc. Or maybe a NoSQL database like Mongo ?With Xojo &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.great-white-software.com\/blog\/2022\/10\/10\/working-with-databases-in-c\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Working with databases in C#&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[1],"tags":[34],"class_list":["post-1444","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-csharp"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/1444","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/comments?post=1444"}],"version-history":[{"count":2,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/1444\/revisions"}],"predecessor-version":[{"id":1454,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/1444\/revisions\/1454"}],"wp:attachment":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/media?parent=1444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/categories?post=1444"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/tags?post=1444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}