Results 1 to 4 of 4

Thread: How to query strings

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    28

    Default How to query strings

    I have a this class:


    Public Class LibertyPIM_DBUsers

    Public DBUserName As String = ""
    Public DBUserPassword As String = ""

    Public Property UserName As String
    Get
    Return DBUserName
    End Get
    Set(ByVal Value As String)
    DBUserName = Value
    End Set
    End Property

    Public Property UserPassword As String
    Get
    Return DBUserPassword
    End Get
    Set(ByVal Value As String)
    DBUserPassword = Value
    End Set
    End Property

    Public Overrides Function ToString() As String
    Return DBUserName & ";;;" & DBUserPassword
    End Function

    Public Sub New()

    End Sub

    Public Sub New(ByVal UserName As String, ByVal Passwd As String)
    Me.DBUserName = UserName
    Me.DBUserPassword = Passwd
    End Sub
    End Class

    I create an XTable with the scheme of this class.

    I want to query by the conditions of DBUserName and DBUserPassword variables. I want to find DBUserName = "Tushar" and DBPassword = "password123"

    Please tell how can I do that? I did not found any tutorial. If I could also use Linq. I am a total newbiew with STSDB. Thanks in advance!

  2. #2

    Default

    Record definition:
            public class LibertyPIM_DBUsers
            {
                public string DBUserName { get; set; }
                public string DBUserPassword { get; set; }
    
                public override string ToString()
                {
                    return DBUserName + ";;;" + DBUserPassword;
                }
            }
    
    Create the database and fill the table:
                using (StorageEngine engine = StorageEngine.FromFile("test.stsdb"))
                {
                    var table = engine.Scheme.CreateOrOpenXTable<int, LibertyPIM_DBUsers>(new Locator("users"));
                    engine.Scheme.Commit();
    
                    for (int i = 0; i < 1000; i++)
                    {
                        var record = new LibertyPIM_DBUsers();
                        record.DBUserName = "user" + i.ToString();
                        record.DBUserPassword = "password" + i.ToString();
    
                        table[i] = record;
                    }
    
                    table.Commit();
                }
    
    Open the database and query the table:
                using (StorageEngine engine = StorageEngine.FromFile("test.stsdb"))
                {
                    var table = engine.Scheme.CreateOrOpenXTable<int, LibertyPIM_DBUsers>(new Locator("users"));
    
                    foreach (var row in table.Where(x => x.Record.DBUserName == "user123" && x.Record.DBUserPassword == "password123"))
                    {
                        Console.WriteLine(row.Record.ToString());
                    }
                }
    

  3. #3
    Junior Member
    Join Date
    Apr 2011
    Posts
    28

    Default HI!

    I was unable to convert the LINQ query code from c# to VB .net as I am completely new to these techniques. I request you if you could post LINQ query code in VB .NET. But hey! Thanks for the example. I learnt something new.

    Tushar

    Quote Originally Posted by a.todorov View Post
    Record definition:
            public class LibertyPIM_DBUsers
            {
                public string DBUserName { get; set; }
                public string DBUserPassword { get; set; }
    
                public override string ToString()
                {
                    return DBUserName + ";;;" + DBUserPassword;
                }
            }
    
    Create the database and fill the table:
                using (StorageEngine engine = StorageEngine.FromFile("test.stsdb"))
                {
                    var table = engine.Scheme.CreateOrOpenXTable<int, LibertyPIM_DBUsers>(new Locator("users"));
                    engine.Scheme.Commit();
    
                    for (int i = 0; i < 1000; i++)
                    {
                        var record = new LibertyPIM_DBUsers();
                        record.DBUserName = "user" + i.ToString();
                        record.DBUserPassword = "password" + i.ToString();
    
                        table[i] = record;
                    }
    
                    table.Commit();
                }
    
    Open the database and query the table:
                using (StorageEngine engine = StorageEngine.FromFile("test.stsdb"))
                {
                    var table = engine.Scheme.CreateOrOpenXTable<int, LibertyPIM_DBUsers>(new Locator("users"));
    
                    foreach (var row in table.Where(x => x.Record.DBUserName == "user123" && x.Record.DBUserPassword == "password123"))
                    {
                        Console.WriteLine(row.Record.ToString());
                    }
                }
    

  4. #4
    Junior Member
    Join Date
    Aug 2012
    Posts
    2

    Default

    But hey! Thanks for the example. I learnt something new.



    -------------------------------
    The Vampire Diaries Season 3 DVD
    United States of Tara Seasons 1-3 DVD

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
2002 - 2014 STS Soft SC. All Rights reserved.
STSdb, Waterfall Tree and WTree are registered trademarks of STS Soft SC.