There are some problems in your database, I have to point to:
Don't use spaces in the columns' names, such as [Our Price]
, [Expected Delivery]
. You can, but it is recommended not to do this. Your identifiers should comply to default rules for regular identifiers.
For monetary or currency values, use MONEY, SMALLMONEY
1 it has many benifits, or even DECIMAL
in some cases. Not NVARCHAR
the way you did in your Products
table.
Use Date and Time data types instead of NVARCHAR
like in [Expected Delivery]
. And the most important one:
Your database isn't normalized this way. You should create a separate tables for Cateogries
, Sports
and Brands
.
For instance:
CREATE TABLE Equipments
(
EquipmentId INT NOT NULL IDENTITY(1, 1)
CONSTRAINT PK_EquipmentId PRIMARY KEY,
EquipmentName NVARCHAR(50) NOT NULL
);
CREATE TABLE Sports
(
SportId INT NOT NULL IDENTITY(1,1)
CONSTRAINT PK_SportId PRIMARY KEY,
SportName NVARCHAR(50)
);
CREATE TABLE SportsEquipments
(
Id INT NOT NULL IDENTITY(1, 1)<sup>2</sup>
CONSTRAINT PK_SportsEquipmentId PRIMARY KEY,
SportId INT NOT NULL
CONSTRAINT FK_SportId_Sports FOREIGN KEY
REFERENCES Sports(SportId),
EquipmentId INT NOT NULL
CONSTRAINT FK_EquipmentId_Equipments FOREIGN KEY
REFERENCES Equipments(EquipmentId)
);
CREATE TABLE Categories
(
CategoryId INT NOT NULL IDENTITY(1, 1)
CONSTRAINT PK_CategoryId PRIMARY KEY,
CategoryName NVARCHAR(50)
);
CREATE TABLE Brands
(
BrandId INT NOT NULL IDENTITY(1, 1)
CONSTRAINT PK_BrandId PRIMARY KEY,
BrandName NVARCHAR(50)
);
CREATE TABLE Products
(
ProductId INT NOT NULL IDENTITY(1, 1)
CONSTRAINT PK_ProductID PRIMARY KEY,
SportId INT NOT NULL
CONSTRAINT FK_SportId_Products
FOREIGN KEY REFERENCES Sports(SportId),
CategoryId INT NOT NULL
CONSTRAINT FK_CategoryId_Categories
FOREIGN KEY REFERENCES Categories(CategoryId),
BrandId INT NOT NULL
CONSTRAINT FK_BrandId_Brands
FOREIGN KEY REFERENCES Brands(BrandId),
"Image" TEXT,
MRP NVARCHAR(50),
OurPrice MONEY,
YouSave MONEY,
ShippingCharges MONEY,
ExpectedDeliveryDate DATETIME
);

How Can I insert into the tables this way?
Later, when inserting into the Products
table, in the insert from, you should display the list of sports, categories and brands as DropDownList
s. But, in this drop down list, you only display the name of the entity. You only display the CategoryName
in the Categories dropdown, BrandName
in the Brands dropdown and so on. And you can do this using the following two properties of the drop down list:
Something like:
dropdown.DataSource = dataset;
dropdown.DataValueField = "CategoryId";
dropdown.DataTextField = "CategoryName";
dropdown.DataBind();
//the same for other entities
Then you should insert only the selected id from the drop down list, and your INSERT
statement would look something like:
INSERT INTO Products (SportId, CategoryId, BrandId, ... )
VALUES
(1, 2, 3, ...);
But How can I Select and Search?
The same in the Search form, you should display these entities as drop down list then search for the products with the id selected by the drop down list:
SELECT ProductId, Name, ...
FROM Products
Where CategoryId = @SelectedCategoryId
AND SportId = @selectedSportId
...
The same with your current problem, you can dynamically created link buttons from these entities, the categories list and sports list as well as other entities. This can be done using the GridView
control, then create a data source and bind it to this grid view. With an <ItemTemplate>
as <asp:LinkButton>
and bind it to the column name selected by your query. If you googled for this, you will find a lot of threads explaining how you can do this. For example :
Hope this is what are you looking for.
1:In some cases, may be you shouldn't use it.
2:In the SportsEquipments
, I used the Id
as a primary key, this way you any equipment can be referenced by many sports. If you want to make the equipment unique for each sports make a composite key(SportId, EquipmentId)
instead.