Coding a Xamarin Android App to Connect to a Cloud Hosted MySQL Database in C#

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video I'm going to create a summer and Android app that connects to a cloud hosted my sequel database to read and insert data the app itself will be a simple not to self type of application and I'll be using Google cloud platform to host the my sequel database this is a prerequisite for the video so if you haven't already got a Google cloud platform account and associated my sequel database then you'll need to set these up first in order to proceed so I'm gonna do the work in Visual Studio 2019 I create a new project I'm gonna create an Android app xamarin gonna create black up okay so once the application has been created when to go into references and manage NuGet packages I'm going to update I just want to update anything that needs it and here and once that's done or to browse for my sequel xamarin done my sequel data they want to install that you know once that's done right click on references add reference they want to go down to system data okay when you go back to solution Explorer right-click the project and add new item add a new class we'll call it constants so I can remove all the using part from system so the case your string will follow this format will be server equals and then server name it's right without the square brackets then port equals port number then user that's the user ID password password and then the name of the database so you can get this connection string from your Google cloud platform my sequel configuration settings so once you've got your connection string just copy and paste it into here so after that my secure connection string we want to add a my sequel select all query so this going to select all from the table we're going to order by this timestamp column then we want to add an insert command so here we're gonna be insert into the table into the columns Nord and timestamp the values held in not in timestamp so not will be the the text that we enter into ends into the Edit box and then timestamp will just be automatically generated based on when the the user click Submit or the submit button save that and do a build just to make sure there are no errors okay so once the builder succeeded what I want to do now is going to resources and layout and activity underscore main die XML open that up this is the page that loads by default when the application starts so this is where all the controls will be for viewing the data and for inserting data let's go into the code view so we start off with a linear layout so have to put it in the layout let's quickly go through a text view that's simply a label says not to self or type nor to self the edit text that will prompt the user to enter some text into the text field button that is for submitting the data and then there's another label I find a little list view that's where all the data that's stored in the table will be will be displayed as not I'm gonna quickly build that okay so what I want to do now is I want to deploy it to my Android device just to take a look at how the layout appears on a form so make sure I've got everything correct so I put my phone and you can see that it's now available so I can deploy the app to my phone so now that the app has deployed to my phone I can see that I've got the label in place I've got the edit text field here I've got a submit button and I've got a list view that that wealth is a label and then a list view that currently doesn't have any items in it so that shows me that the layout is is what I want so far so with the layout now in place I can start to work in the main activity CS file so within here I'm going to write the C sharp cord that will go to the database table retrieve all the notes in the table and write it write them to the ListView and then put in a button click event that will take the text in the edit text field and push that into the database just going to make some references here system collections and then my sequel seagull client using system the top of the class I'm going to create an array list the list of you and an edit text field now in the oncreate method below this set content view you can find the list view that we've created earlier it has a name of LST Knox under the sound for the edit text field I want to create a button like button submit then we want to create a click event that's created the event down there to save that to create method you and this is why we're going to get the data and write it to the ListView so this does it creates a nice equal connection using the connection string that we created in the constants class earlier similarly we're creating a my sequel command using the select all query that we used earlier that we created earlier so this creates a data reader and if the table has rows then while the rules are being read add whatever's in the or the second column because the first column will be zero whatever is in the first in that in the second column add that to the not array so in this case it will be whatever not we've we've added and finally so what this line does is he sets the adapter for the ListView to be a new array adapter of this type of layout so simple expandable list item and the avoid thing here is we're using the notes array so in other words this this ListView will contain this array finally want to call this method from oncreate which means that the the method will be called when the app runs and will see in the list all of the knots so we won't need to have any additional interaction with the app to see all the notes in the in the list okay I want to just build that just make sure they're not Harris case once that's built I want to doing the deploy so we can see there that when the app is deployed to the phone the Lord knots method is running and it's going to the database going to the table and pulling down any notes that are found within the second column of that table so there are three items here in the button submit click method it's going to delete that line I want to put in the code that writes data to the table based on the edit text field I'm gonna create a date/time here and that will be the date stamp timestamp so we can just edit this we should move so don't need to do a career query on this one so making the connection we open in the database and we're adding not and time stamp based on the values of the edit text text property and the date/time now down here we're clearing the notes array because we don't want to add to the array want to clear it then just set in the edit text field to empty and then reloading the not so we can see the NADA we've just added so save and build and I'm going to do a deploy so what I can do now I can put a knot in the text field it's submit so you see that's put into the table it's it's it's then come back into Lord knots its pulled down then you not do another one submit so that's working as I'd expect it to so thanks for watching the video if you have any questions you have any problems with with what I've shown you put it in the comments down below and I'll get back to you
Info
Channel: IndieRevo
Views: 20,798
Rating: undefined out of 5
Keywords: c#, csharp, c# development, c# coding, csharp coding, csharp development, development, coding, xamarin, xamarin android, xamarin development, xamarin android development, xamarin android coding, mysql, mysql development, mysql coding, google cloud platform, visual studio, how to, set up, setting up
Id: Vx8OnFoPGco
Channel Id: undefined
Length: 21min 4sec (1264 seconds)
Published: Wed Apr 29 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.