Visual Studio 2010 WinForm中的ComboBox问题 [英] Problem with ComboBox in Visual Studio 2010 WinForm
问题描述
你好,
我是数据库和编程的新手,我在WinForm上的ComboBox遇到问题
我正在使用MSSQL Management Studio 2008/SQL 2008& Visual Studio 2010
我有2个表>>产品与服务tblCategory
tblCategory的表结构>>
Hello,
I m new to Database and Programming, i have a problem with ComboBox on WinForm
I am Using MSSQL Management Studio 2008 / SQL 2008 & Visual Studio 2010
i have 2 Tables >> tblProduct & tblCategory
Table Structure for tblCategory>>
CatId..... int >>Primary Key
Name.......nvarchar(100)
Description ... nvarchar (255)
Image ..........image
tblProduct的表结构
Table Structure for tblProduct
ProductID .... int>> Primary Key
Name...........nvarchar(100)
Category.......nvarchar(100)
Description....nvarchar(255)
Price..........money
DateAdded .... DateTIme
Supplier......nvarchar(100)
Image ...... image
Notes .......nvarchar(255)
我想从tblCategory在组合框中显示类别名称,并想更新tblProduct中的类别字段.但我无法做到这一点?
任何人都可以在与Primary& amp;的表关系方面提供帮助外键以及如何显示和更新类别
Cheers
I want to Display Categories Name in a ComboBox from tblCategory and want to Update the Category Field in tblProduct. but i m unable to do that ?
anyone can help in Table Relationship with Primary & Foreign Key and how to display and update the Categories
Cheers
推荐答案
首先,您不应该将"Category Desc"存储在tblProduct中,而应使用CategoryID.至于填满组合箱的问题...
使用这样的SQL查询:SELECT NAME,CATEGORYID FROM TBLCATEGORY
使用它来获取数据并将组合框与数据表绑定.
分别使用名称"和类别ID"设置数据成员和值成员.
本文包含一个小样本,将对您有所帮助:
http://msdn.microsoft.com/en-us/library/x8ybe6s2 (v = vs.80).aspx [
First you should not store the "Category Desc" in tblProduct, use the CategoryID instead. As far as the question of filling up the combo box...
Use a SQL query like this : SELECT NAME, CATEGORYID FROM TBLCATEGORY
use this to fetch the data and bind the combo box with the datatable.
set the data member and value member with the "Name" and "CategoryID" respectively.
This article contains a small sample, would be helpful:
http://msdn.microsoft.com/en-us/library/x8ybe6s2(v=vs.80).aspx[^]
这篇关于Visual Studio 2010 WinForm中的ComboBox问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!