Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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


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)


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
Posted
Updated 28-Sep-11 9:13am
v2
Comments
Sergey Alexandrovich Kryukov 28-Sep-11 15:11pm    
Unable... what's the problem?
--SA
laxi300 28-Sep-11 15:19pm    
Well the problem is very simple

i have2 tables "tblCategory" and "tblProduct"

i want to call Category Name in a combobox from tblCategory on addProduct winform and want to update the Category field in tblProduct

1 solution

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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900