我不斷收到此錯誤,「當前值'String.Empty'類型與期望的'System.Boolean'類型不兼容,當我嘗試循環來自Azure表的一大堆實體,我只是使用Azure的新手,所以這可能非常容易,我得到的錯誤。嘗試通過Azure表中的實體循環時出錯
我的代碼:
private void registerButton_Click(object sender, RoutedEventArgs e)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"));
// Create the table client
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
// Get the data service context
TableServiceContext serviceContext = tableClient.GetDataServiceContext();
// Create a new customer entity
user = new UserDetailsEntity();
//Setting the fields of the new userEntity
user.username = usernameText.Text;
user.password = passwordText.Text;
user.subscriptionID = subText.Text;
user.subscriptionName = subscriptionNameText.Text;
user.thumbprint = thumbprintText.Text;
user.email = emailText.Text;
user.phoneNumber = "3530" + numberText.Text;
int rowCount = 1;
CloudTableQuery<UserDetailsEntity> Query = (from en in serviceContext.CreateQuery<UserDetailsEntity>("userdetails")
select en).AsTableServiceQuery<UserDetailsEntity>();
//error occurs in the next line
foreach (UserDetailsEntity ent in Query)
{
rowCount++;
}
user.RowKey = rowCount.ToString();
// Add the new customer to the people table
serviceContext.AddObject("userdetails", user);
// Submit the operation to the table service
serviceContext.SaveChangesWithRetries();
//Set the variables so they can be retrieved when the next screen loads
Application.Current.Properties["username"] = usernameText.Text;
Application.Current.Properties["password"] = passwordText.Text;
Window1 userHome = new Window1();
this.Close(); //to close Password window
userHome.Show(); //to show Main form
}
乾杯的答覆,錯誤是發生上線 的foreach(在查詢UserDetailsEntity ENT) 這就是爲什麼我很困惑,爲什麼錯誤是發生 – StevenR 2012-03-30 13:32:41
@StevenR對不起,我錯過了,我有更新了我的答案,以幫助你更好地理解這一點 – 2012-03-30 13:47:37
非常感謝,我會盡力做你的建議 – StevenR 2012-03-30 14:27:40