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. What do I find on google ?

Hi,
To connect to a SQL Server from a Xamarin app (using Visual Studio, so some instructions might change), I followed this process:

  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

My code connects to a SQL database located on a server (not localhost) and then searches for an account number to check if it exists. The code is:

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
    }`

I've created a web service app (asp.net) that provides services to my Xamarin Forms apps so the mobile app will login to SQL Server via the web service and indeed perform all SQL actions (Select, Insert, Delete, etc) using the web service framework. I would suggest that's the way to go for you and/or welcome to cover in more detail my solution (which is generic SQL server forms access) in case that's of interest to you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.