locked
[UWP][C#]Store char in SQLite? RRS feed

  • Question

  • I have

    <TextBlock Text="&#xE1CB;" FontFamily="Segoe MDL2 Assets"/>
    I want to store and load it in C#, How to store Text="&#xE1CB;" to SQLite?
    Thursday, July 27, 2017 1:46 AM

Answers

  • @Nguyen_Thanh_Liem,

    OK. So the problem is that the backslash in C# is a special character and it is for compile time when as a prefix, not runtime. At runtime we cannot do it like this. At runtime we can try the following:

     mytest.Text = Char.ConvertFromUtf32(0xE1CB);

    So here you are using the following to show your icon at runtime:

    0xE1CB

    In this way you can get the value out without problem.

    Best regards,

    Barry



    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.


    Tuesday, August 1, 2017 2:06 AM
  • Nguyen_Thanh_Liem,

    Are you now asking for how to do the data-binding? Pseudo code cloud like this:

    public class Database
    {
        private int TagInt { get; set; }
        public string Tag
        {
            get
            {
                return ((char)TagInt).ToString();
            }
        }
    }

    Where TagInt will be the saved value reading from database; And you have a read-only Tag property to be bind.

    <TextBlock Text="{x:Bind Tag, Mode=OneWay}" FontFamily="Segoe MDL2 Assets" />

    Various ways exists depends on your implementation details. You will add code to RaisePropertyChanged for Tag whenever TagInt changes.


    I build UWPs: Arrnage Pro, Cloud Resource Tools

    Tuesday, August 1, 2017 5:58 AM

All replies

  • Hello,

    Use text is already enough to store this kind of value.

    I use the following code to create the property:

      private string chartext;
    
            public string CharText
            {
                get { return chartext; }
                set { chartext = value; }
            }

    And add it to a collection like the following:

     SqliteHelper2 sqlhelper = new SqliteHelper2();
    
            private ObservableCollection<ThreadDetailsModel> testmodel = new ObservableCollection<ThreadDetailsModel>();
            public ObservableCollection<ThreadDetailsModel> Threadsmodel { get { return this.testmodel; } }
    
           public TestVM()
            {
                sqlhelper.CreateThreadsTable();
                testmodel.Add(new ThreadDetailsModel {CharText= "&#xE1CB",
                    Guid = "22535954-c1a3-4b6c-b25e-4d35af1d5b6a",
                    IsAnswered="No",
                    ThreadTitle= "[UWP][C#]Store char in SQLite?",
                    ThreadURL= "https://social.msdn.microsoft.com/Forums/windowsapps/en-US/22535954-c1a3-4b6c-b25e-4d35af1d5b6a/uwpcstore-char-in-sqlite?forum=wpdevelop",
                    Casetype="New",
                    ID=0,             
                });
                sqlhelper.InsertorReplaceThreadTable(testmodel[0]);
            }

    Then here is the result in SQLite:

    And in SQLite it already shows this url about the types in SQLite. By the way, the method of SQLite is packaged by myself. You can find some blogs about how to use SQLite.

    Best regards,

    Barry



    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.

    Friday, July 28, 2017 3:04 AM
  •  public string CharText
            {
                get { return chartext; }
                set { chartext = value; }
            }

    Is different with??

     public string CharText { get; set ; }


    Friday, July 28, 2017 4:46 AM
  • @Nguyen_Thanh_Liem,

    OK I understand your problem. You mean that it does not show the right icon. Sorry I haven't understand it. I will check it in details.

    Best regards,

    Barry


    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.

    Friday, July 28, 2017 7:55 AM
  • @Nguyen_Thanh_Liem,

    Consider do a convert here in your code. When you set the text from code behind you can use:

     mytest.Text = "\xE1CB";

    In this way the icon will show properly. So here you need to set a method to convert the original

    &#xE1CB

    to

    \xE1CB

    Best regards,

    Barry




    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.

    Friday, July 28, 2017 9:15 AM
  • When save to SQLite I use &#xE1CB

    When show on TextBlock I SubTring to xE1CB  and plus '\' . But it loss \ 

    Friday, July 28, 2017 9:40 AM
  • @Nguyen_Thanh_Liem,

    How did you do that? Can you read the msdn doc first https://msdn.microsoft.com/en-us/library/h21280bw.aspx

    You need to understand that slash is always used for specific content. So if you want to write a backslash you need to use "\\" or @"\". If you just use "\" it will miss this.

    Best regards,

    Barry


    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.

    Monday, July 31, 2017 6:53 AM
  • As you said, to store to SQLite I store a string like &#xE1CB

    Then I want to show it from SQLite I must use TextBlock.Text = "\xE1CB"

    When I add \ to prefix of xE1CB, it's miss \

    Monday, July 31, 2017 7:00 AM
  • @Nguyen_Thanh_Liem,

    OK. So the problem is that the backslash in C# is a special character and it is for compile time when as a prefix, not runtime. At runtime we cannot do it like this. At runtime we can try the following:

     mytest.Text = Char.ConvertFromUtf32(0xE1CB);

    So here you are using the following to show your icon at runtime:

    0xE1CB

    In this way you can get the value out without problem.

    Best regards,

    Barry



    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.


    Tuesday, August 1, 2017 2:06 AM
  • Hi Nguyen,

    What you are trying to save, at the end of the day, is a HEX value. How about save it as integer directly:

    int x = 0xE768; // Save x into your db.

    To use it:

    int y = 0xE768; // Read from db to y.
    return ((char)y).ToString();



    I build UWPs: Arrnage Pro, Cloud Resource Tools

    Tuesday, August 1, 2017 4:07 AM
  • My Database.cs:

    public class Database
    {
       public string TAG {}
       public string NAME{}
    }

    My ListView

    <ListView>
      <DataTemplate>
           <StackPanel>
               <TextBlock x:Name = "txtTAG" Text{Binding}/>
               <TextBlock x:Name = "txtNAME" Text{Binding}/>
           </StackPanel>
      </DataTemplate>
    </ListView>

    How to show correct Tag from SQLite to ListView



    Tuesday, August 1, 2017 5:11 AM
  • My Database.cs:

    public class Database
    {
       public string TAG {}
       public string NAME{}
    }

    My ListView

    <ListView>
      <DataTemplate>
           <StackPanel>
               <TextBlock x:Name = "txtTAG" Text{Binding}/>
               <TextBlock x:Name = "txtNAME" Text{Binding}/>
           </StackPanel>
      </DataTemplate>
    </ListView>

    How to show correct Tag from SQLite to ListView




    Tuesday, August 1, 2017 5:12 AM
  • Nguyen_Thanh_Liem,

    Are you now asking for how to do the data-binding? Pseudo code cloud like this:

    public class Database
    {
        private int TagInt { get; set; }
        public string Tag
        {
            get
            {
                return ((char)TagInt).ToString();
            }
        }
    }

    Where TagInt will be the saved value reading from database; And you have a read-only Tag property to be bind.

    <TextBlock Text="{x:Bind Tag, Mode=OneWay}" FontFamily="Segoe MDL2 Assets" />

    Various ways exists depends on your implementation details. You will add code to RaisePropertyChanged for Tag whenever TagInt changes.


    I build UWPs: Arrnage Pro, Cloud Resource Tools

    Tuesday, August 1, 2017 5:58 AM
  • Thank you Saar!
    Tuesday, August 1, 2017 11:18 AM
  • Thank you Barry!
    Tuesday, August 1, 2017 11:19 AM