简体   繁体   English

WPF-如何将组合框选择的值添加到数据库

[英]WPF - How to add combobox selected value to database

tblProd p = new tblProd();
p.categoryname=cb_category.SelectedValue.ToString();

I get the string as " Demo.tbl_category " I get the name of the table as string instead of a category name. 我得到的字符串为“ Demo.tbl_category ”我得到的表名称为字符串而不是类别名称。 I have two properties in my category model category name and description. 我的类别模型的类别名称和描述有两个属性。 I have bound the combobox source to observablecollection of category and I have categoryname as the displaymemberpath in combobox . 我已经将combobox源绑定observablecollection category的observablecollection ,并且我将categoryname作为comboboxdisplaymemberpath

plz help me.thanks in advance. 请帮助我。谢谢。

I m using linq . 我正在使用linq。

You are getting an instance of the object and its ToString . 您正在获取对象及其ToString的实例。

SelectedValue contains an instance of the object tbl_category SelectedValue包含对象tbl_category的实例

Try changing to. 尝试更改为。

p.categoryname=((tbl_category)cb_category.SelectedValue).categoryname;

or 要么

p.categoryname=cb_category.SelectedValue.categoryname;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM