2016-08-09 14 views
1

誰かが私を助けることができるかどうか不思議ですか?Azureテーブルデータの取得/キャスト

私は、テーブルにデータをアップロード/ダウンロードすると思われるアプリを持っています。テーブルへのデータ書き込みに問題はありません。読書は問題です。ここで

は私が持っているものです。

まず私のクラスである:

Imports Microsoft.WindowsAzure.Storage.Table 

Public Class TimeRecord 
Inherits Microsoft.WindowsAzure.Storage.Table.TableEntity 
Implements Microsoft.WindowsAzure.Storage.Table.ITableEntity 

Private _Project1 As String 

Public Property Project1 As String 
    Get 
     Return _Project1 
    End Get 
    Set(ByVal value As String) 
     _Project1 = value 
    End Set 
End Property 


Public Property Data As String 
Public Property Category1 As String 
Public Property Description1 As String 
Public Property HRS1 As String 
Public Property MINS1 As String 

Public Property Project2 As String 
Public Property Category2 As String 
Public Property Description2 As String 
Public Property HRS2 As String 
Public Property MINS2 As String 


end class 

'next is the Upload, which is working fine and uploading all data to the table 

Public NewRecord As New TimeRecord 
Public CloudNewRecord As New TimeRecord 

' Finishing and uploading 
Private Sub Button_Finish_Click(sender As Object, e As EventArgs) Handles Button_Finish.Click 

    Call VariableAssign() ' that is where we assigning data to NewRecord.xxx="blah blah" etc 

    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("tdb") 

    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) 

    Call TimeCounter() 
    exSubUpload = False 
End Sub 


' **here is where I do have a problem casting**.... **I think I`m missing something in the Class declaration** 

' Retrieve from cloud 
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("tdb") 

    Dim retrieveOperation As TableOperation 
    Dim retrievedResult As TableResult 

    retrieveOperation = TableOperation.Retrieve(ComboBox1.SelectedItem, _date) 
    ' it does retrieve all data and keep it in retrievedResult 

    retrievedResult = table.Execute(retrieveOperation) 

    **' that is I`m having problems - probably lack of knowledge/understanding - of how to cast all the data back to the class.** 
    CloudNewRecord = retrievedResult.Result 
    Debug.Print(CloudNewRecord.Project1) 


End Sub 

私はちょうどなぜ私がテーブルにNewRecordとを書き込むことができ、理解していないが、私はそれを読むことができませんテーブルから同じCloudNewRecordクラスへ? VB.netで良い例が見つかりませんでした。

何か助けていただければ幸いです。

答えて

0

GOT IT !!!!

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).Project1) 
関連する問題