-
Jun 23rd, 2018, 06:55 PM
#1
Thread Starter
Fanatic Member
How do Xamarin forms connect to SQL Server ?
How do I process the xamarin forms that connect to SQL Server and export data to the listView ? I'm looking for this simple example xamarin forms that connect to SQL Server and display data to the listView. What do I find on google ?
-
Jun 23rd, 2018, 08:23 PM
#2
Re: How do Xamarin forms connect to SQL Server ?
I don't know... what did you find on google? Try googling xamarin sql server .... sometimes just going with the basics works best.
I found this: https://forums.xamarin.com/discussio...-to-sql-server
Which talks about using a REST WebAPI to talk to SQL Server. The xamarin app doesn't do it directly, but invokes the queries through a REST API call over the web.
-
Jun 25th, 2018, 03:36 AM
#3
Re: How do Xamarin forms connect to SQL Server ?
Yep i second that, your Xamarin app wont talk directly to SQL Server.
Think about it this way, when you finally publish your mobile app and make it usable on a mobile phone, if it did have a direct link to SQL Server then you would only be able to use that app when you were wirelessly attached to the same network as your SQL Server is on (and therefore your app isn't really very mobile is it!!)
Almost all mobile apps will use a REST web service of some sort to get data,
Your Xamarin forms app will make calls to your web service, your web service talks to the SQL Server and gets your data into a class object or list of object, and then converts it and returns it as JSON to your mobile app. Your mobile app then once it has received that data converts the JSON back into a class object or a list of objects which you can then use in your mobile app.
Your first step before you do any mobile development should be to create your web service, write you code to pull data form SQL server and get you web service to return data.
Once you have at least one web service call working and returning data successfully you can then look to hook it up to your mobile app.
Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you
-
Jun 29th, 2018, 11:40 PM
#4
Thread Starter
Fanatic Member
Re: How do Xamarin forms connect to SQL Server ?
I'm looking for this simple example on google no, do you know site that supports demo library using REST WebAPI with SQL Server? The page you submitted has no example https://forums.xamarin.com/discussio...-to-sql-server
-
Mar 11th, 2020, 11:54 PM
#5
Lively Member
Re: How do Xamarin forms connect to SQL Server ?
1.Add in a System.Data reference to your project
2.Add in a using directive "using System.Data.SqlClient"
3.Define connection string and open the connection using SqlConnection(connectionString)
4.Manipulate database as normal
string connectionString = @"Server=<ipAddress>;Database=<DBName>;User Id=<username>;Password=<password>;Trusted_Connection=true";
string databaseTable = "<yourDBTableName>";
string referenceAccountNumber = "0001134919";
string selectQuery = String.Format("SELECT * FROM {0} WHERE [Account_Number] = '{1}' ", databaseTable, referenceAccountNumber);
try
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
//open connection
connection.Open();
SqlCommand command = new SqlCommand(selectQuery, connection);
command.Connection = connection;
command.CommandText = selectQuery;
var result = command.ExecuteReader();
//check if account exists
var exists = result.HasRows;
}
}
catch (Exception exception)
{
#region connection error
AlertDialog.Builder connectionException = new AlertDialog.Builder(this);
connectionException.SetTitle("Connection Error");
connectionException.SetMessage(exception.ToString());
connectionException.SetNegativeButton("Return", delegate { });
connectionException.Create();
connectionException.Show();
#endregion
}
-
Mar 13th, 2020, 04:00 AM
#6
Re: How do Xamarin forms connect to SQL Server ?
1.Add in a System.Data reference to your project
2.Add in a using directive "using System.Data.SqlClient"
3.Define connection string and open the connection using SqlConnection(connectionString)
4.Manipulate database as normal
No No No
Do not even think about doing this approach, your on a mobile device not a desktop app. It will not work
Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you
-
Mar 13th, 2020, 04:08 AM
#7
Re: How do Xamarin forms connect to SQL Server ?
I'm looking for this simple example on google no, do you know site that supports demo library using REST WebAPI with SQL Server?
There are plenty of example of building a REST WebApi talking to SQL server
if you want to do it in normal .net
https://docs.microsoft.com/en-us/asp...aspnet-web-api
if you want to use .Net Core
https://docs.microsoft.com/en-us/asp...=visual-studio
However if your asking for a simple example to for using a Web API with Xamarin then you are out of luck, its not simple. Its perfectly learnable but you need to know MVVM and if you dont know it you spend sometime understanding it.
There are no short cuts, if you look on YouTube there are now a lot of good tutorials on Xamarin and a lot of using Xamarin with MVVM and Web API if you search for those terms.
Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|