I have a category table with 4 columns as and i have made Id as identity as well as Primarykey
ID Categoryname Cimage
Then i have a subcategory table as
ID1 Subcategoryname Simage Description Catid .
In category page
I have a Textbox (for entering name of category) and Image . I have binded it to gridview.
so my gridview displays Textbox data and image.
In my Subcategory page
I have a dropdownlist ,Textbox1 (for entering name of subcategory) , Image , Textbox2 (for entering description)
I populate the dropdownlist from category table(categoryname)
and the rest data should be saved into database and display in gridview..
I am stuck with subcategory page .My data enters into database but unable to display in gridview....
how should i relate 2 tables with id and catid .
and how to write the ado.net connections for subcategory page..
I have been trying for weeks but dint succeed...
can anyone help me out with detailed coding. please
Thanks in advance .
Loading

Iftikar HussainRank #423 · 5.9K reputationPosted Jul 11, 2013, 10:41 PM EDT
and in your code
try the above code and check weather your first issue is resolved or not
Regards,
Iftikar
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 10, 2013, 4:37 AM EDT
You can do like this
Regards,
Iftikar
antony victor90 reputationPosted Jul 11, 2013, 9:39 PM EDT
But can u help me . I am stuck with 2 things
When ever i try to upload the same image twice in category page with same name ,it uploads
but when i delete one of the image then the other image also doesn't show up .
But the row still exists with other data....
Second issue in Subcategory table is that image uploads twice everytime i click the button.
I have attached the category and subcategory page below.
CATEGORY PAGE
SUBCATEGORY PAGE
Please suggest me.
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 11, 2013, 9:47 PM EDT
Regards,
Iftikar
antony victor90 reputationPosted Jul 11, 2013, 10:03 PM EDT
where they were implementing the employee details.
I have kept the sp name same but changed the sp code in database.
SqlCommand com = new SqlCommand("insert_employee", con);
SqlCommand com = new SqlCommand("delete_employee", con);
SqlCommand com = new SqlCommand("update_employee", con);
so i have changed it to SqlCommand com = new SqlCommand("insert_category", con);
Here i am implementing a Customer Management System,
where in ,if i try to upload the same image twice ,it uploads but
when i try to delete any one of that , the other image link doesnt show up
, but data still exists in database.
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 11, 2013, 10:06 PM EDT
Regards,
Iftikar
antony victor90 reputationPosted Jul 11, 2013, 10:11 PM EDT
This is the query in sp written..
antony victor90 reputationPosted Jul 11, 2013, 10:56 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 11, 2013, 11:02 PM EDT
Regards,
Iftikar
antony victor90 reputationPosted Jul 11, 2013, 11:23 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 11, 2013, 11:25 PM EDT
Regards,
Iftikar
antony victor90 reputationPosted Jul 12, 2013, 12:59 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 12, 2013, 1:05 AM EDT
put the break point in the highlighted line
Regards,
Iftikar
antony victor90 reputationPosted Jul 12, 2013, 1:45 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 12, 2013, 1:47 AM EDT
Regards,
Iftikar
antony victor90 reputationPosted Jul 12, 2013, 2:21 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 12, 2013, 2:28 AM EDT
select * from subcategory where cid=@cid
Regards,
Iftikar
antony victor90 reputationPosted Jul 12, 2013, 3:38 AM EDT
antony victor90 reputationPosted Jul 13, 2013, 12:20 AM EDT
I have a problem, In my subcategory table , i have columns
id1 sname simage desc cid
But i want to display in gridview as
category subcategory subcatimage description ...
The category column , i populated it from category table onto dropdownlist in subcategorypage
and that showed up in dropdownlist in subcategory page and i am able to delete rows via cid.
The problem now is how do i display the category column in subcategory gridview ?
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 13, 2013, 11:07 AM EDT
You want to show the Category Name in Subcategory gridview. or You want to show
Category id.
if you want Category name then try this query and bind it to grid:
SELECT C.Cname AS Category,S.Cid,S.sname AS SubCategory,S.simage AS subcatimage, S.desc AS description
FROM subcategory S
INNER JOIN Category c
ON S.Cid=C.Cid
any problem reply
antony victor90 reputationPosted Jul 14, 2013, 9:32 PM EDT
In my gridview ,i am cascading data(cname) into ddl from previous category table.
following is the below code
private void bindgrid1()
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
DataSet ds = new DataSet();
SqlCommand com = new SqlCommand("select * from subcategory where cid=@cid", con);
com.Parameters.AddWithValue("@cid", DropDownList1.SelectedValue);
SqlDataAdapter sqlda = new SqlDataAdapter(com);
sqlda.Fill(ds);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
con.Close();
sqlda.Fill(ds);
if (ds.Tables[0].Rows.Count == 0)
{
Label3.Visible = true;
GridView2.Visible = false;
Label3.Text = "No images added yet";
}
else
{
Label3.Visible = false;
GridView2.Visible = true;
GridView2.DataSource = ds;
GridView2.DataBind();
sqlda.Dispose();
con.Close();
}
}
Design of my table is
category
id cname cimage
subcategory
id1 sname simage desc cid.
Here what i have done is, i am storing id value into ddl from category table and also storing the same into cid of subcategory table so that i can relate two tables.
and one more thing is , i dont have cid common in both the tables.
could you guide me please sir.
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 14, 2013, 9:37 PM EDT
You should able to retrieve all subcategory by cid
Regards,
Iftikar
antony victor90 reputationPosted Jul 14, 2013, 9:50 PM EDT
I m able to retreive all subcategory details, but now a small correction
In my subcategory Gridview , i also want to display cname(categoryname) which i pulled in ddl from category table...
coz i dont have a cname(categoryname) in my subcategory table .
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 14, 2013, 9:57 PM EDT
Regards,
Iftikar
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 14, 2013, 10:01 PM EDT
try this code:
private void bindgrid1()
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
DataSet ds = new DataSet();
string query = "SELECT C.cname AS Category,S.cid,S.sname AS SubCategory,S.simage AS subcatimage, S.desc AS description FROM subcategory S INNER JOIN Category c ON S.Cid=C.id where S.Cid=@cid";
SqlCommand com = new SqlCommand(query, con);
com.Parameters.AddWithValue("@cid", DropDownList1.SelectedValue);
SqlDataAdapter sqlda = new SqlDataAdapter(com);
sqlda.Fill(ds);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
con.Close();
sqlda.Fill(ds);
if (ds.Tables[0].Rows.Count == 0)
{
Label3.Visible = true;
GridView2.Visible = false;
Label3.Text = "No images added yet";
}
else
{
Label3.Visible = false;
GridView2.Visible = true;
GridView2.DataSource = ds;
GridView2.DataBind();
sqlda.Dispose();
con.Close();
}
}
antony victor90 reputationPosted Jul 14, 2013, 11:28 PM EDT
I got an error saying
SqlException was unhandled By UserCode.
Incorrect syntax near the keyword 'desc'.
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 14, 2013, 11:32 PM EDT
Regards,
Iftikar
antony victor90 reputationPosted Jul 14, 2013, 11:42 PM EDT
id cname cimage
id (1,1) int;
cname varchar(50);
cimage varchar(250)
My subcategory Table
id1 sname simage desc cid
id1 (1,1) int ;
sname varchar(50);
siamge varchar(250);
desc varchar(250);
cid int
sp for category table
Insert category
Delete category
update category
sp for Subcategory table
Insert subcategory
Delete Subcategory
Update Subcategory
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 15, 2013, 12:25 AM EDT
select id1,sname,siamge ,desc where cid=@cid
Regards,
Iftikar
antony victor90 reputationPosted Jul 15, 2013, 3:29 AM EDT
it works fine when i type, select * from subcategory where cid=@cid;
But by using above query i cant get cname into gridview , which is in the category table.
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 15, 2013, 3:39 AM EDT
Regards,
Iftikar