I am stuck with this peculiar problem... I am unable to fetch data from the database to the dropdownlist...
The situation is like this: I have two tables named tblPropertyCategory and tblPropertySubCategory..
I have joined these two tables in the database inorder to combine separate columns of these two tables
named PCName and PSCName.. I want to display the data of both of these table as a whole... I was successful
in doing this and even wrote the stored procedure for that but when I binded the dropdownlist ,It doesnt show
any value neither it display any error.. On debugging it is passing the appropriate parameter..
I dont know what is happening.. I think dere is some error in the stored procedure or may in my codes...
Please have a look:
STORED PROCEDURE
CREATE Procedure [dbo].[tblProperty_SelectProperty]
--Your Parameter Goes Here
@iPCId INT
AS
select PSCName as PC--Virtual Table named PC which will be used for Storing the Union Data
from tblPropertyCategory INNER JOIN tblPropertySubCategory
ON tblPropertyCategory.PCId=tblPropertySubCategory.PCId
where tblPropertyCategory.PCId=tblPropertySubCategory.PCId and
tblPropertyCategory.PCId=@iPCId
union
select PCName
from tblPropertyCategory INNER JOIN tblPropertySubCategory
ON tblPropertyCategory.PCId=tblPropertySubCategory.PCId
where tblPropertyCategory.PCId=tblPropertySubCategory.PCId and
tblPropertyCategory.PCId=@iPCId
BLL
public DataSet SelectProperty()
{
DBAccess db = new DBAccess();
db.AddParameter("@iPCId", iPCId);
return db.ExecuteDataSet("[tblProperty_SelectProperty]");
}
Go to SQL/Server enterprise manager (or LinqPad or Visual Studio) and execute the stored procedure. Do you get any records? Are you connecting to the right database? Is there any data in the database that you are conencted to?
By the way - in your query you don't need the first part of the where clause, The inner join already ensures that the values of PCId are equal in the two tables.
geniusvishal
Star
14076 Points
2794 Posts
Unable to fetch data from the database
Feb 25, 2012 11:38 AM|LINK
Hello Guys,
I am stuck with this peculiar problem... I am unable to fetch data from the database to the dropdownlist...
The situation is like this: I have two tables named tblPropertyCategory and tblPropertySubCategory..
I have joined these two tables in the database inorder to combine separate columns of these two tables
named PCName and PSCName.. I want to display the data of both of these table as a whole... I was successful
in doing this and even wrote the stored procedure for that but when I binded the dropdownlist ,It doesnt show
any value neither it display any error.. On debugging it is passing the appropriate parameter..
I dont know what is happening.. I think dere is some error in the stored procedure or may in my codes...
Please have a look:
STORED PROCEDURE
CREATE Procedure [dbo].[tblProperty_SelectProperty]
--Your Parameter Goes Here
@iPCId INT
AS
select PSCName as PC--Virtual Table named PC which will be used for Storing the Union Data
from tblPropertyCategory INNER JOIN tblPropertySubCategory
ON tblPropertyCategory.PCId=tblPropertySubCategory.PCId
where tblPropertyCategory.PCId=tblPropertySubCategory.PCId and
tblPropertyCategory.PCId=@iPCId
union
select PCName
from tblPropertyCategory INNER JOIN tblPropertySubCategory
ON tblPropertyCategory.PCId=tblPropertySubCategory.PCId
where tblPropertyCategory.PCId=tblPropertySubCategory.PCId and
tblPropertyCategory.PCId=@iPCId
BLL
public DataSet SelectProperty()
{
DBAccess db = new DBAccess();
db.AddParameter("@iPCId", iPCId);
return db.ExecuteDataSet("[tblProperty_SelectProperty]");
}
C# Codebehind
tblProperty objProperty = new tblProperty();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
bindddlProperty();
}
}
public void bindddlProperty()
{
ddlProperty.DataSource = objProperty.SelectProperty();
ddlProperty.Visible = true;
ddlProperty.DataTextField = "PC";
ddlProperty.DataValueField = "PCId";
ddlProperty.DataBind();
ddlProperty.Items.Insert(0, "---Select Property Type---");
}
Please have and look & suggest how to rectify it..
Regards and Thanx in Advance...
My Website
www.dotnetvishal.com
jerryjoseph
Contributor
6740 Points
1257 Posts
Re: Unable to fetch data from the database
Feb 25, 2012 11:46 AM|LINK
Put a break point on
and check the value of ddlProperty.DataSource.
linkedin | twitter | www.jerryjoseph.net
geniusvishal
Star
14076 Points
2794 Posts
Re: Unable to fetch data from the database
Feb 25, 2012 11:51 AM|LINK
My Website
www.dotnetvishal.com
geniusvishal
Star
14076 Points
2794 Posts
Re: Unable to fetch data from the database
Feb 25, 2012 11:55 AM|LINK
This is what I want to display:
My Website
www.dotnetvishal.com
jerryjoseph
Contributor
6740 Points
1257 Posts
Re: Unable to fetch data from the database
Feb 25, 2012 11:56 AM|LINK
Count is 0 which means there is nothing in the DataSource.
Check the value of db.ExecuteDataSet("[tblProperty_SelectProperty]");
Set break point on
return db.ExecuteDataSet("[tblProperty_SelectProperty]");and use "Add Watch"
linkedin | twitter | www.jerryjoseph.net
geniusvishal
Star
14076 Points
2794 Posts
Re: Unable to fetch data from the database
Feb 25, 2012 12:14 PM|LINK
Yes It is not getting debugged.. Y is it so??
Ny Solution??
My Website
www.dotnetvishal.com
Paul Linton
Star
13407 Points
2533 Posts
Re: Unable to fetch data from the database
Feb 26, 2012 03:26 AM|LINK
Go to SQL/Server enterprise manager (or LinqPad or Visual Studio) and execute the stored procedure. Do you get any records? Are you connecting to the right database? Is there any data in the database that you are conencted to?
By the way - in your query you don't need the first part of the where clause, The inner join already ensures that the values of PCId are equal in the two tables.
Sailaja Redd...
Member
452 Points
81 Posts
Re: Unable to fetch data from the database
Feb 26, 2012 06:48 AM|LINK
public void bindddlProperty()
{
ddlProperty.DataSource = objProperty.SelectProperty();
ddlProperty.Visible = true;
ddlProperty.DataTextField = "PC";
ddlProperty.DataValueField = "PCId";
ddlProperty.DataBind();
ddlProperty.Items.Insert(0, "---Select Property Type---");
}
Procedure "tblProperty_SelectProperty" is returning only PC Column but not "PCId".
So data is not binded.
Change the procedure to return PC and PCID fileds.
Hope this helps:-)
Sailaja.
MyTechnical Blog