How to get single string data from SQLITE database ?

  //Get all image url from Brading table
    public string GetColorResourceFromDatabase(string key)
    {
        try
        {
            //string value = (from i in mSqlConnection.Table<BrandingInfoModel>() select key).ToString();
            string value = mSqlConnection.Query<string>("SELECT " + key + " FROM data").ToString();
            return value;
        }
        catch (Exception e)
        {
            string error = e.Message;
            return null;
        }
    }

I have written the method that returns the string from the database but it returns the null value.
Can anyone help that how to execute query which returns the string value from database ?

Answers

  • MarlonRibeiroMarlonRibeiro USMember ✭✭✭
    edited July 2017

    @Jaymin You're not getting a single string, but a List.
    I'd need to see your model, but try something like:

    mSqlConnection.Table<BrandingInfoModel>().FirstOrDefault()?.Key.ToString()

  • JayminJaymin USMember ✭✭

    @MarlonRibeiro
    Here is a model

    [Table(TableConst.TABLE_BRANDING)]
    public class BrandingInfoModel
    {
    public int id { get; set; }
    public string title { get; set; }
    public string logo_image { get; set; }
    public string menu_banner_image { get; set; }
    public string splash_screen_image { get; set; }
    public string tile_corner_radius { get; set; }
    public string primary_color { get; set; }
    public string secondary_color { get; set; }
    public string tertiary_color { get; set; }
    public string background_color { get; set; }
    public string gradient_topcolor { get; set; }
    public string searchfield_color { get; set; }
    public string tile_icon_color { get; set; }
    public string card_icon_color { get; set; }
    public string card_iconbg_color { get; set; }
    public string gradient_bottomcolor { get; set; }
    public string header_color { get; set; }
    public string tile_color { get; set; }
    public string tile_shadow_color { get; set; }
    public bool apply_tile_shadow { get; set; }
    public string cta_color { get; set; }
    public string menu_background_color { get; set; }
    public string directioncta_icon_color { get; set; }
    public string header_text_color { get; set; }
    public string header_icon_color { get; set; }
    public string tile_text_color { get; set; }
    public string cta_icon_color { get; set; }
    public string cta_text_color { get; set; }
    public string menu_text_color { get; set; }
    public string menu_chevron_color { get; set; }
    public string text_color { get; set; }
    public string chevron_color { get; set; }
    public string searchfield_icon_color { get; set; }
    public string searchfield_text_color { get; set; }
    public string directioncta_color { get; set; }

    }
    

    Please check it and let me know how can i get my desired result ?

Sign In or Register to comment.