none
System.Data.SQLClient Does not exist - Xamarin RRS feed

  • Question

  • I am new to Xamarin and I am trying to create a simple cross platform app that talks to the database using ADO.NET.

    To do this I need to use "System.Data.SqlClient;" in the code.


    I am trying to code into the "MainPage.xaml.cs" file in the Shared folder but it says "System.Data.SqlClient;" doesn't exist but if I go to the "MainPage.xaml.cs" file in the UWP folder I am able to use "System.Data.SqlClient;"

    Is there something I'm missing? Why can't I use it in the Shared Folder?


    Wednesday, April 18, 2018 11:29 AM

Answers

  • You'll need to add a reference for System.Data


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by patreilly Thursday, April 19, 2018 8:54 AM
    Wednesday, April 18, 2018 12:45 PM
    Moderator

All replies

  • You'll need to add a reference for System.Data


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by patreilly Thursday, April 19, 2018 8:54 AM
    Wednesday, April 18, 2018 12:45 PM
    Moderator
  • Are you using a .NET Standard project? AFAIK there is no PCL support for System.Data.SqlClient so you would need to update your Xamarin Forms to .NET Standard. See the below link:

    https://stackoverflow.com/questions/47284115/how-to-add-system-data-sqlclient-nuget-package-into-net-portable-pcl4-5-profi?rq=1

    It isn't clear where the database is located but if it's on the device you may want to consider using SQLite instead.


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Wednesday, April 18, 2018 12:53 PM

  • I right clicked on the Dependencies folder and clicked Add Reference.

    I then was able to add the System.Data.SqlClient.dll

    This then allowed me to to use the following code without error

    using System.Data;
    using System.Data.SqlClient;

    However, when I try to use the following code I get an error:

    using (SqlConnection conn = new SqlConnection(conString))
                {
                    conn.Open();
    
                    SqlCommand command = new SqlCommand("SELECT job_name FROM tbl_job; ", conn);
    
                }
    

    It tells me "the type or namespace 'SqlConnection' could not be found".

    Shouldn't it be working to now that I have SqlClient added to my file?

    Wednesday, April 18, 2018 1:47 PM
  • See the following 

    https://channel9.msdn.com/Shows/XamarinShow/Snack-Pack-15-Upgrading-to-XamarinForms-to-NET-Standard


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Wednesday, April 18, 2018 2:37 PM
    Moderator
  • See the following 

    https://channel9.msdn.com/Shows/XamarinShow/Snack-Pack-15-Upgrading-to-XamarinForms-to-NET-Standard


    FYI, referred to at the stackoverflow link in my post.

    Paul ~~~~ Microsoft MVP (Visual Basic)

    Wednesday, April 18, 2018 6:32 PM
  • Hello patreilly,

    >>System.Data.SQLClient Does not exist - Xamarin

    Try to use SqlLite database to store and retrieve objects in mobile device rather than Sql Server. It's too heavy for mobile. For Xamarin I suggest you need to repost a new thread to Xamarin Forum for better solution and support.

    Best Regards,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, April 19, 2018 7:40 AM
    Moderator
  • See the following 

    https://channel9.msdn.com/Shows/XamarinShow/Snack-Pack-15-Upgrading-to-XamarinForms-to-NET-Standard


    FYI, referred to at the stackoverflow link in my post.

    Paul ~~~~ Microsoft MVP (Visual Basic)

    Hi Paul,

    My bad on this, didn't realize you had posted this.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, April 19, 2018 8:51 AM
    Moderator
  • I think I got it working.

    I was missing the System.Data.SqlClient NuGet Package.

    To get it I right clicked on dependencies and selected Manage NuGet Packages and searched for System.Data.SqlClient and installed it.

    Thursday, April 19, 2018 8:54 AM