我正在为UWP编写一个应用程序。
我尝试根据此答案link使用数据绑定。
以下是我的课程:
CREATE PROCEDURE [dbo].[GetMaxId] (
@id varchar(50)
@table varchar(50)
)
AS
BEGIN
DECLARE @sql NVARCHAR(MAX);
SET @sql = N'SELECT MAX(@id) FROM @table';
SET @sql = REPLACE(REPLACE(@sql, '@id', QUOTENAME(@id)), '@table', QUOTENAME(@table));
EXEC sp_executesql @sql;
END; -- GetMaxId
以下是代码:
public class Billing
{
public string first_name { get; set; }
public string last_name { get; set; }
public string company { get; set; }
public string address_1 { get; set; }
public string address_2 { get; set; }
public string city { get; set; }
public string state { get; set; }
public string postcode { get; set; }
public string country { get; set; }
public string email { get; set; }
public string phone { get; set; }
}
public class Shipping
{
public string first_name { get; set; }
public string last_name { get; set; }
public string company { get; set; }
public string address_1 { get; set; }
public string address_2 { get; set; }
public string city { get; set; }
public string state { get; set; }
public string postcode { get; set; }
public string country { get; set; }
}
public class RootObject
{
public int id { get; set; }
public int parent_id { get; set; }
public string status { get; set; }
public string order_key { get; set; }
public string currency { get; set; }
public string version { get; set; }
public bool prices_include_tax { get; set; }
public string date_created { get; set; }
public string date_modified { get; set; }
public int customer_id { get; set; }
public double discount_total { get; set; }
public double discount_tax { get; set; }
public double shipping_total { get; set; }
public double shipping_tax { get; set; }
public double cart_tax { get; set; }
public double total { get; set; }
public double total_tax { get; set; }
public Billing billing { get; set; }
public Shipping shipping { get; set; }
public string payment_method { get; set; }
public string payment_method_title { get; set; }
public string transaction_id { get; set; }
public string customer_ip_address { get; set; }
public string customer_user_agent { get; set; }
public string created_via { get; set; }
public string customer_note { get; set; }
public string date_completed { get; set; }
public string date_paid { get; set; }
public string cart_hash { get; set; }
public List<object> line_items { get; set; }
public List<object> tax_lines { get; set; }
public List<object> shipping_lines { get; set; }
public List<object> fee_lines { get; set; }
public List<object> coupon_lines { get; set; }
}
public ObservableCollection<RootObject> Orders { get; set; }
List<RootObject> rootObjectData = JsonConvert.DeserializeObject<List<RootObject>>(products);
foreach (RootObject root in rootObjectData)
{
string date = root.date_created;
string name = root.billing.first_name + root.billing.last_name ;
Orders = new ObservableCollection<RootObject> { new RootObject { date_created = date,billing = name } };
}
我收到此错误:billing = name
如何修复此错误? 也许这很简单,但我找不到解决方案。 谢谢你的帮助!!
答案 0 :(得分:1)
使用billing = name我有这样的错误:无法将类型'string'隐式转换为'Milano.InWork.Billing'
当然会发生此错误,班级billing
中的RootObject
数据类型为Billing
,这是您定义的另一个类。
仅从您的代码中我想您只想在first_name
中将last_name
和root.billing
显示为字符串,然后您可以更改public Billing billing { get; set; }
中的代码RootObject
{1}}课程为public string billing { get; set; }
。