locked
Looking for Azure Table Query example in VB RRS feed

  • Question

  • Hello Guys! 

    Can someone help me ?

    Any help is appreciated.

    I do have an app that works with Azure tables. No problem writing data to the table. Reading is the problem.

    Here is what I have:

    ' Finishing and uploading THIS PART WORKS AWESOME Private Sub Button_Finish_Click(sender As Object, e As EventArgs) Handles Button_Finish.Click exSubUpload = True Call VariableAssign() Dim accountname As String = "projects" Dim accountkey As String = My.Settings.StorageKey Dim creds As StorageCredentials = New StorageCredentials(accountname, accountkey) Dim account As CloudStorageAccount = New CloudStorageAccount(creds, useHttps:=True) Dim client As CloudTableClient = account.CreateCloudTableClient() Dim table As CloudTable = client.GetTableReference("ttdb") table.CreateIfNotExists() NewRecord.Data = _date NewRecord.PartitionKey = ComboBox1.SelectedItem NewRecord.RowKey = NewRecord.Data ' Magically we write data to the cloud in Minesota Dim insertoperation As TableOperation insertoperation = TableOperation.InsertOrReplace(NewRecord) table.Execute(insertoperation) exSubUpload = False End Sub ' Retrieve from cloud HERE IS THE PROBLEM. IT RETRIEVES INFO BUT I CANT CAST IT TO SAME CLASS VARIABLE NEWRECORD Private Sub RetrieveFromCloud() Dim accountname As String = "projects" Dim accountkey As String = My.Settings.StorageKey Dim creds As StorageCredentials = New StorageCredentials(accountname, accountkey) Dim account As CloudStorageAccount = New CloudStorageAccount(creds, useHttps:=True) Dim client As CloudTableClient = account.CreateCloudTableClient() Dim table As CloudTable = client.GetTableReference("ttdb") Dim retrieveOperation As TableOperation Dim retrievedResult As TableResult retrieveOperation = TableOperation.Retrieve(ComboBox1.SelectedItem, _date) retrievedResult = table.Execute(retrieveOperation)

    'HERE IS THE BAD LINE, HOW CAN I CAST RESULT TO THE NEWRECORD CLASS? ?????????????NewRecord = retrievedResult.Result..... End Sub

    As you can see I get data I need I just need to put it back into the Class variables:

    

    

    Here is the NewRecord Class. Do I have to add anything extra there?

    'TimeRecord class
    
    Public Class TimeRecord
        Inherits Microsoft.WindowsAzure.Storage.Table.TableEntity
    
    
        Property Data As String
        ' Property PartitionKey As String
        ' Property RowKey As String
    
        Property Project1 As String
        Property Category1 As String
        Property Description1 As String
        Property HRS1 As String
        Property MINS1 As String
    
        Property Project2 As String
        Property Category2 As String
        Property Description2 As String
        Property HRS2 As String
        Property MINS2 As String
    
    
    End Class

    • Edited by Alex20122012 Sunday, August 7, 2016 2:09 AM added class
    Saturday, August 6, 2016 11:02 PM

Answers

  • GOT IT! 

     Private Sub RetrieveFromCloud()
            'Try
    
            Dim accountname As String = "projects"
            Dim accountkey As String = My.Settings.StorageKey
            Dim creds As StorageCredentials = New StorageCredentials(accountname, accountkey)
            Dim account As CloudStorageAccount = New CloudStorageAccount(creds, useHttps:=True)
            Dim client As CloudTableClient = account.CreateCloudTableClient()
            Dim table As CloudTable = client.GetTableReference("ttdb")
    
            Dim retrieveOperation As TableOperation
            Dim retrievedResult As TableResult
    
            retrieveOperation = TableOperation.Retrieve(Of TimeRecord)(ComboBox1.SelectedItem, _date)
            retrievedResult = table.Execute(retrieveOperation)
    
            Debug.Print(DirectCast(retrievedResult.Result, TimeRecord).Category1)
          
    
        End Sub


    Alex


    • Marked as answer by Alex20122012 Tuesday, August 9, 2016 8:46 PM
    • Edited by Alex20122012 Tuesday, August 9, 2016 8:46 PM updated string
    Tuesday, August 9, 2016 8:45 PM

All replies

  • Hello Alex,

    It would be great if you can open up a Support ticket for this issue.

    You may open a support ticket with our technical team for much detailed analysis of the issue: http://azure.microsoft.com/en-us/support/options/


    Regards,
    Sumanth BM


    Sunday, August 7, 2016 9:56 AM
  • Is there other way to get a support? I thought its free with pay as you go subscription hich I have. 

    Its says:

    You’ll need to buy a support plan before you can submit a technical support request.


    Alex

    Sunday, August 7, 2016 2:56 PM
  • How can I cast 'Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity' to type 'TimeRecord' ?

    It has to be a way of doing that. I was looking at the C# examples and they just specify class there "CustomerEntity"

    Syntaxis in VB is different unless I`m doing smth wrong...

    // Create a retrieve operation that takes a customer entity.
    TableOperation retrieveOperation = TableOperation.Retrieve<CustomerEntity>("Smith", "Ben");
    
    // Execute the retrieve operation.
    TableResult retrievedResult = table.Execute(retrieveOperation);
    
    // Print the phone number of the result.
    if (retrievedResult.Result != null)
       Console.WriteLine(((CustomerEntity)retrievedResult.Result).PhoneNumber);
    else
       Console.WriteLine("The phone number could not be retrieved.");


    Alex

    Sunday, August 7, 2016 8:48 PM
  • I think the type of the result (retrievedResult.Result.) that you get is DynamicTableEntity and your class (TimeRecord) is TableEntity. Do you want to try implementing ITableEntity instead of inheriting the TableEntity.

    Or,

    You can look at "Retrieve a single entity" section from this link https://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-how-to-use-tables/

    It seems like you can cast it. e.g. NewRecord = (TimeRecord)retrievedResult.Result


    Michael Sync: blog: http://michaelsync.net

    Monday, August 8, 2016 5:30 AM
  • Thank you.

    I think I have incomplete TimeRecord class. The problem is I can`t find anything on the net written in VB. Only C#. Syntax's  is different.

    I`ve done more reading and I figured (Ihope I`m correct I need to add the following line to the class:

    Public Class TimeRecord
        Inherits Microsoft.WindowsAzure.Storage.Table.TableEntity
        
    ' I have to add this??
    Implements Microsoft.WindowsAzure.Storage.Table.ITableEntity
    
    
        Private _Project1 As String
    ' Does all my properties should look like this? (Get:Set)
        Public Property Project1 As String
            Get
                Return _Project1
            End Get
            Set(ByVal value As String)
                _Project1 = value
            End Set
        End Property
    ....
    ....
    ....
    
    End Class

    I`f I make my class similar to one below written in C# I believe

    public class CustomerEntity : TableEntity
    {
        public CustomerEntity(string lastName, string firstName)
        {
            this.PartitionKey = lastName;
            this.RowKey = firstName;
        }
    
        public CustomerEntity() { }
    
        public string Email { get; set; }
    
        public string PhoneNumber { get; set; }
    }

    all will work....

    Thank you


    Alex

    Monday, August 8, 2016 1:38 PM
  • GOT IT! 

     Private Sub RetrieveFromCloud()
            'Try
    
            Dim accountname As String = "projects"
            Dim accountkey As String = My.Settings.StorageKey
            Dim creds As StorageCredentials = New StorageCredentials(accountname, accountkey)
            Dim account As CloudStorageAccount = New CloudStorageAccount(creds, useHttps:=True)
            Dim client As CloudTableClient = account.CreateCloudTableClient()
            Dim table As CloudTable = client.GetTableReference("ttdb")
    
            Dim retrieveOperation As TableOperation
            Dim retrievedResult As TableResult
    
            retrieveOperation = TableOperation.Retrieve(Of TimeRecord)(ComboBox1.SelectedItem, _date)
            retrievedResult = table.Execute(retrieveOperation)
    
            Debug.Print(DirectCast(retrievedResult.Result, TimeRecord).Category1)
          
    
        End Sub


    Alex


    • Marked as answer by Alex20122012 Tuesday, August 9, 2016 8:46 PM
    • Edited by Alex20122012 Tuesday, August 9, 2016 8:46 PM updated string
    Tuesday, August 9, 2016 8:45 PM