Showing posts with label empty. Show all posts
Showing posts with label empty. Show all posts

Sunday, March 25, 2012

Dropdownlist with stored procedure problem

Hi Everyone,

I am trying to load the data into the dropdownlist using stored procedure. But when I run the code, the dropdownlist is empty. The code is shown below. Please help! Thanks.

public DataSet getProvince()
{
DataSet ds = new DataSet();
SqlParameter myParam;

string conString;
SqlConnection myConnection;

conString = ConfigurationManager.AppSettings["connectionString"];
myConnection = new SqlConnection(conString);

SqlCommand cmd = new SqlCommand("stored_procedure_GetProvinces", myConnection);

SqlDataAdapter adpt = new SqlDataAdapter(cmd);

try
{

cmd.CommandType = CommandType.StoredProcedure;
myParam = cmd.Parameters.Add("@.province_key", SqlDbType.Int);
myParam.Direction = ParameterDirection.Output;

myParam = cmd.Parameters.Add("@.province_name", SqlDbType.NVarChar, 200);
myParam.Direction = ParameterDirection.Output;

adpt.Fill(ds, "Provinces");

myConnection.Close();

}
catch (SqlException ex)
{
Response.Write("Error: " + ex.Message);
}
return ds;
}

-----------

create procedure stored_procedure_GetProvinces( @.province_key int output, @.province_name nvarchar (200) output)AsSelect @.province_key=province_key, @.province_name=province_name From provinceGO

--------

<asp:DropDownList id="Dropdownlist_Province" DataValueField="province_key" DataTextField="province_name" DataSource='<%# getProvince() %>' Runat="server" >
</asp:DropDownList>

----------

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[province]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[province]
GO

CREATE TABLE province (
province_key int IDENTITY PRIMARY KEY,
province_name nvarchar (200) NULL
)
GO

INSERT INTO province(province_name) VALUES
('- Select -');
GO
INSERT INTO province (province_name) VALUES
('Ontario');
GO
INSERT INTO province (province_name) VALUES
('Alberta');
GO
INSERT INTO province (province_name) VALUES
('British Columbia');
GO
INSERT INTO province (province_name) VALUES
('Manitoba');
GO
INSERT INTO province(province_name) VALUES
('New Brunswick');
GO
INSERT INTO province (province_name) VALUES
('Newfoundland');
GO
INSERT INTO province (province_name) VALUES
('Northwest Territories');
GO
INSERT INTO province (province_name) VALUES
('Nova Scotia');
GO
INSERT INTO province (province_name) VALUES
('Nunavut');
GO
INSERT INTO province (province_name) VALUES
('Prince Edward Island');
GO
INSERT INTO province (province_name) VALUES
('Quebec');
GO
INSERT INTO province (province_name) VALUES
('Saskatchewan');
GO
INSERT INTO province (province_name) VALUES
('Yukon Territory');
GO

What is the value of your parameter?|||

what you need is:

Select province_key, province_nameFrom province

also, you need to modify your .NET code and remove the parameter part. The way you are doing, your proc will return just one set of values from the table, since there is no WHERE condition and your variables can only have one value at a time, SQL server will just pick a row at random and assign the values to the variables. Assuming you want to see ALL the values since you are binding it to a drop down, you just need the SELECT statement with the columns (without any variables). Also, look into using an ExecuteReader which is faster than filling a dataadapter and a dataset.

|||

bullpit:

What is the value of your parameter?

Sorry, I don't know. Thanks.

|||

ndinakar:

what you need is:

Select province_key, province_nameFrom province

also, you need to modify your .NET code and remove the parameter part. The way you are doing, your proc will return just one set of values from the table, since there is no WHERE condition and your variables can only have one value at a time, SQL server will just pick a row at random and assign the values to the variables. Assuming you want to see ALL the values since you are binding it to a drop down, you just need the SELECT statement with the columns (without any variables). Also, look into using an ExecuteReader which is faster than filling a dataadapter and a dataset.

After I modify my code and my stored procedure. I still get the empty dropdownlist. Please help. Thanks.

|||did you change the proc to the way I suggested? Also please post your new .NET code..|||

ndinakar:

did you change the proc to the way I suggested? Also please post your new .NET code..

My updated code is shown below. Thanks!

create procedure

stored_procedure_GetProvinces

(

@.province_key

intoutput,

@.province_name nvarchar (200)

output

)

As

Select

province_key, province_nameFromprovince

GO

--------

publicDataSet getProvince()

{

DataSet ds =newDataSet();SqlParameter myParam;string conString;SqlConnection myConnection;

conString =

ConfigurationManager.AppSettings["connectionString"];

myConnection =

newSqlConnection(conString);SqlCommand cmd =newSqlCommand("stored_procedure_GetProvinces", myConnection);SqlDataAdapter adpt =newSqlDataAdapter(cmd);try

{

cmd.CommandType =

CommandType.StoredProcedure;

adpt.Fill(ds,

"Provinces");

myConnection.Close();

}

catch (SqlException ex)

{

Response.Write(

"Error: " + ex.Message);

}

return ds;

}

--------- the end -------

|||

ndinakar:

what you need is:

Select province_key, province_nameFrom province

also, you need to modify your .NET code and remove the parameter part. The way you are doing, your proc will return just one set of values from the table, since there is no WHERE condition and your variables can only have one value at a time, SQL server will just pick a row at random and assign the values to the variables. Assuming you want to see ALL the values since you are binding it to a drop down, you just need the SELECT statement with the columns (without any variables). Also, look into using an ExecuteReader which is faster than filling a dataadapter and a dataset.

I have just tried using ExecuteReader. And I still get empty dropdownlist. Please help. Thanks.

SqlCommand objCmd;

SqlConnection objConn;

SqlDataReader dataReader;

String strSql;

objConn =newSqlConnection(ConfigurationManager.AppSettings.Get("ConnectionString"));

strSql ="EXECUTE stored_procedure_GetProvinces";

objCmd =newSqlCommand(strSql, objConn);

try

{

objConn.Open();

dataReader = objCmd.ExecuteReader(

CommandBehavior.CloseConnection);

Dropdownlist_Provinces.DataSource = dataReader;

Dropdownlist_Provinces.DataTextField =

"province_name";

Dropdownlist_Provinces.DataValueField =

"province_name";

Dropdownlist_Provinces.DataBind();

}

catch

{

}

finally

{

objConn.Close();

objConn.Dispose();

}

|||

Your stored proc would be like this:

create procedure dbo.stored_procedure_GetProvincesAsSelect province_key, province_nameFrom province GO

Then your .NET code could be someting like this: You might have to convert it to C#.

Protected objConAs New SqlConnection(ConfigurationSettings.AppSettings("conn"))pubic sub....Dim myCommandAs SqlCommandmyCommand =New SqlCommand()myCommand.Connection = objconmyCommand.CommandText ="stored_procedure_GetProvinces"myCommand.CommandType = CommandType.StoredProcedureIf objCon.State = 0Then objCon.Open()dpunits.DataSource = SqlCmd1.ExecuteReaderdpunits.DataTextField ="province_name" dpunits.DataValueField ="province_key"dpunits.DataBind()objCon.Close()end sub

|||

ndinakar:

Your stored proc would be like this:

create procedure dbo.stored_procedure_GetProvincesAsSelect province_key, province_nameFrom province GO

Then your .NET code could be someting like this: You might have to convert it to C#.

Protected objConAs New SqlConnection(ConfigurationSettings.AppSettings("conn"))pubic sub....Dim myCommandAs SqlCommandmyCommand =New SqlCommand()myCommand.Connection = objconmyCommand.CommandText ="stored_procedure_GetProvinces"myCommand.CommandType = CommandType.StoredProcedureIf objCon.State = 0Then objCon.Open()dpunits.DataSource = SqlCmd1.ExecuteReaderdpunits.DataTextField ="province_name" dpunits.DataValueField ="province_key"dpunits.DataBind()objCon.Close()end sub

What is SqlCmd1 in SqlCmd1.ExecuteReader ? Thanks.

|||

MayLam:

ndinakar:

Your stored proc would be like this:

create procedure dbo.stored_procedure_GetProvincesAsSelect province_key, province_nameFrom province GO

Then your .NET code could be someting like this: You might have to convert it to C#.

Protected objConAs New SqlConnection(ConfigurationSettings.AppSettings("conn"))pubic sub....Dim myCommandAs SqlCommandmyCommand =New SqlCommand()myCommand.Connection = objconmyCommand.CommandText ="stored_procedure_GetProvinces"myCommand.CommandType = CommandType.StoredProcedureIf objCon.State = 0Then objCon.Open()dpunits.DataSource = SqlCmd1.ExecuteReaderdpunits.DataTextField ="province_name" dpunits.DataValueField ="province_key"dpunits.DataBind()objCon.Close()end sub

What is SqlCmd1 in SqlCmd1.ExecuteReader ? Thanks.

I replace SqlCmd1 with myCommand. And it is working now. Thank you very much for your help! Bye!

May

Monday, March 19, 2012

Drop List problem

Hi,

When I'm creating a dropdown list prompt from a field which has large number of distinct values (OrgUnit codes etc.) I get an empty list.

Can anyone advice on this issue ?

Is your drop down list bound to a dataset.

Thanks,

vnswathi.

|||

Hi,

We are using Cognos right now and moving to SSRS. In Cognos we don't have this problem and this problem occur in SSRS with all kind of field types if it has large amount of distinct values. Maybe it's a restriction in SSRS ? and if so, maybe you know the upper limit ?

Thanks,

Yuval

|||

hi

i dont think there would be any problem with the fields size

u need to create a separate dataset for the drop down list prompt.

and then choose the from query parameter...

hope it solves your issue.

regards,

www.snktheone.com

Sunday, March 11, 2012

DROP DATABASE Question

Hello,
in our project i have to drop an existing sql server database and
immediately create a new (and empty) one with exactly the same name. MSDN
says that in case of dropping a database also the physical files on the
harddrive are deleted but this is not the case, as sql server complains that
there's already a file with that name on disk.
Is there a way to delete also the disk files of a database using T-SQL or do
i have to choose a different approach?
Thanks in advance
ChristianIn 6.5 and older, the database files were not deleted when you execute DROP
DATABASE. As of 7.0,
they are. If you are seeing something different, you have either hit a bug i
n the product (unlikely)
or may have some problems in your scripts.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"chris" <chris@.discussions.microsoft.com> wrote in message
news:68AFCD1C-85B6-4661-9332-3F50830BF386@.microsoft.com...
> Hello,
> in our project i have to drop an existing sql server database and
> immediately create a new (and empty) one with exactly the same name. MSDN
> says that in case of dropping a database also the physical files on the
> harddrive are deleted but this is not the case, as sql server complains th
at
> there's already a file with that name on disk.
> Is there a way to delete also the disk files of a database using T-SQL or
do
> i have to choose a different approach?
> Thanks in advance
> Christian|||Check the default file location. Could it be that you previously created a
database with the same name in this location, but later abandoned it and
started creating databases with files in another location while the default
file location was left unchanged?
The easiest way would be to check your default location and check your file
system.
ML
http://milambda.blogspot.com/|||Thank you very much for your replies.
I found that before dropping the database it was set OFFLINE to disconnect
users and in this case the files remain on disk. I set it to SINGLE_USER
instead and then it worked.
Chris
"chris" wrote:

> Hello,
> in our project i have to drop an existing sql server database and
> immediately create a new (and empty) one with exactly the same name. MSDN
> says that in case of dropping a database also the physical files on the
> harddrive are deleted but this is not the case, as sql server complains th
at
> there's already a file with that name on disk.
> Is there a way to delete also the disk files of a database using T-SQL or
do
> i have to choose a different approach?
> Thanks in advance
> Christian|||> I found that before dropping the database it was set OFFLINE to disconnect
> users and in this case the files remain on disk.
That was news for me. Thanks for sharing the information, Chris.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"chris" <chris@.discussions.microsoft.com> wrote in message
news:B5951FCB-2434-4241-969C-02BF0E7816A3@.microsoft.com...
> Thank you very much for your replies.
> I found that before dropping the database it was set OFFLINE to disconnect
> users and in this case the files remain on disk. I set it to SINGLE_USER
> instead and then it worked.
> Chris
> "chris" wrote:
>

Sunday, February 19, 2012

drillthrough problems with remote reports

After spending some time searching the forums for other people with these same issues, I've come up empty handed and decided it was time to make a post. I'm using the VS2005 WebForms ReportViewer object to embed remote (i.e. not using rdlc) reports on an asp.net page. When the page is first rendered, I have code to set the ServerReport.ReportPath property to the location of a parent-level report on my report server. Each record in this report has a drillthrough link to another server report, and each record in this detail-level report has ANOTHER drillthrough link to a third report that is an even more detailed view of the data. So in short, I have a set of drillthrough reports that can go three levels deep and the top-level report is rendered by default when the page is first viewed.

The behavior that I would expect is that when I click on the drillthrough links in the first or second report, the ReportViewer would incur a postback and automatically do the plumbing to render the appropriate drillthrough report with the proper parameters passed in by the parent report. I would also expect the "back" button in the ReportViewer toolbar to correctly navigate back up the tree to the top-level parent report without any additional programming.

The behavior that I'm ACTUALLY seeing is that the drillthrough works fine from TopLevelReport to MidLevelReport works fine, but when I click to drillthrough from MidLevelReport to BottomLevelReport, the ReportViewer re-renders MidLevelReport with different parameters, as if I had gone back to TopLevelReport and clicked on a different record. However, if at this point I click on a drillthrough link in the new rendering of MidLevelReport, it correctly navigates to BottomLevelReport.

Also, the back button functionality is unpredictable; sometimes I receive this exception when clicking the back button from MidLevelReport:

System.InvalidOperationException: Back call without drillthrough report at Microsoft.Reporting.WebForms.ReportViewer.Toolbar_Back(Object sender, EventArgs e) at Microsoft.Reporting.WebForms.ToolbarControl.OnBack(Object sender, EventArgs e) at Microsoft.Reporting.WebForms.BackGroup.BackButton_Click(Object sender, EventArgs e) at Microsoft.Reporting.WebForms.ScriptSwitchImage.EnabledImage_Click(Object sender, EventArgs e) at Microsoft.Reporting.WebForms.HoverImage.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

When clicking the back button on BottomLevelReport, instead of throwing the above exception it correctly navigates back to MidLevelReport, but then the back button is disabled and I can't go back up to TopLevelReport.

I've experimented with hooking into the ReportViewer.DrillThrough and ReportViewer.Back events to see if maybe I'm just expecting the ReportViewer to handle some under-the-hood plumbing that I'm supposed to code myself, such as updating the value of ServerReport.ReportPath or calling ServerReport.Refresh. I won't go into lengthy details of all the combinations of coding I've tried, but all of them introduced some sort of incorrect navigation behavior or outright exceptions. What I really need is for somebody experienced with using ReportViewer to display remote drillthrough reports more than two levels deep to tell me exactly what I need to do in my DrillThrough and/or Back event handlers in order to make the ReportViewer behave in the expected way.

Thanks in advance to anybody who replies; I've been stuck on this problem for a couple of days now and I'm starting to consider abandoning the idea of using ReportViewer for this project.

vigg:

After spending some time searching the forums for other people with these same issues, I've come up empty handed and decided it was time to make a post. I'm using the VS2005 WebForms ReportViewer object to embed remote (i.e. not using rdlc) reports on an asp.net page. When the page is first rendered, I have code to set the ServerReport.ReportPath property to the location of a parent-level report on my report server. Each record in this report has a drillthrough link to another server report, and each record in this detail-level report has ANOTHER drillthrough link to a third report that is an even more detailed view of the data. So in short, I have a set of drillthrough reports that can go three levels deep and the top-level report is rendered by default when the page is first viewed.

The behavior that I would expect is that when I click on the drillthrough links in the first or second report, the ReportViewer would incur a postback and automatically do the plumbing to render the appropriate drillthrough report with the proper parameters passed in by the parent report. I would also expect the "back" button in the ReportViewer toolbar to correctly navigate back up the tree to the top-level parent report without any additional programming.

The behavior that I'm ACTUALLY seeing is that the drillthrough works fine from TopLevelReport to MidLevelReport works fine, but when I click to drillthrough from MidLevelReport to BottomLevelReport, the ReportViewer re-renders MidLevelReport with different parameters, as if I had gone back to TopLevelReport and clicked on a different record. However, if at this point I click on a drillthrough link in the new rendering of MidLevelReport, it correctly navigates to BottomLevelReport.

Also, the back button functionality is unpredictable; sometimes I receive this exception when clicking the back button from MidLevelReport:

System.InvalidOperationException: Back call without drillthrough report at Microsoft.Reporting.WebForms.ReportViewer.Toolbar_Back(Object sender, EventArgs e) at Microsoft.Reporting.WebForms.ToolbarControl.OnBack(Object sender, EventArgs e) at Microsoft.Reporting.WebForms.BackGroup.BackButton_Click(Object sender, EventArgs e) at Microsoft.Reporting.WebForms.ScriptSwitchImage.EnabledImage_Click(Object sender, EventArgs e) at Microsoft.Reporting.WebForms.HoverImage.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

When clicking the back button on BottomLevelReport, instead of throwing the above exception it correctly navigates back to MidLevelReport, but then the back button is disabled and I can't go back up to TopLevelReport.

I've experimented with hooking into the ReportViewer.DrillThrough and ReportViewer.Back events to see if maybe I'm just expecting the ReportViewer to handle some under-the-hood plumbing that I'm supposed to code myself, such as updating the value of ServerReport.ReportPath or calling ServerReport.Refresh. I won't go into lengthy details of all the combinations of coding I've tried, but all of them introduced some sort of incorrect navigation behavior or outright exceptions. What I really need is for somebody experienced with using ReportViewer to display remote drillthrough reports more than two levels deep to tell me exactly what I need to do in my DrillThrough and/or Back event handlers in order to make the ReportViewer behave in the expected way.

Thanks in advance to anybody who replies; I've been stuck on this problem for a couple of days now and I'm starting to consider abandoning the idea of using ReportViewer for this project.

I am facing the exact same issues and am in the same boat. Depending on whether these multilevel drillthrough server reports work properly, I might abandon or use the Reportviewer for this project. its very crucial.

I am also having another issue. In my "mid level drill through report", the Dundas chart that i am using isnt showing either. It shows when its not a drillthrough but the top level report. But not in the drillthrough mode. HELP PLEASE !!

|||

I try this before and it works perfectly but i don't get your problem exactly so i advice you to check the examples in this link

http://www.gotreportviewer.com/

|||

Same issue here, with a variation...

I've got a report that takes a parameter, and another similar report without a parameter. Both have drillthroughs to detail reports. On the report without the parameter, the drillthrough works just fine. On the report *with* the parameter, clicking on the drillthrough link simply reloads the page. It does a postback, the event targets appear to be set, but the drillthrough event does not get fired. I discovered that the very fact that I am setting the parameters (eg, ReportViewer1.ServerReport.SetParameters(_params)) is causing the drillthrough event to not fire--I set the parameters on one of the non-parameterized reports to an empty list of parameters, and behold, the drillthrough event is no longer fired.

Is this a bug with the report viewer, or is there another way to set parameters that doesn't break the drillthrough event? I've tried setting the callback both before and after the parameters are set, so I'm really out of ideas.

Tuesday, February 14, 2012

Drilldown doesn't work on wildcard search!

I have a report parameter â'spare part numberâ' thatâ's configured like this:
Data type: string, non-queried (empty list), no default value. This field is
rendered as a text box in preview. I also have other parameters but these are
all based on queries and datasets and are therefore rendered as drop downs.
What I really want is the user to be able to ask for a report on many spare
part numbers in one go. I canâ't get this to work, so if you know how, please
let me know.
What works is to leave this field empty and have a filter like:
=Fields! PART_NR.Value Like =iif(trim( Parameters!SparePart.Value
)="","*",Parameters!SparePart.Value )
When I enter a valid spare part number (e.g.: 3215323) or do a wildcard
search (e.g.: 32*) The correct result is shown, but my drilldown no longer
works. Clicking the â'+â' sends the report back to me collapsed (This is in
preview mode).
Anyone know anything about this?
Regards
AK411MultiValued parameters are being added to the Yukon version of RS. There
are other posts in this newsgroup that may have a solution, but I do not
have one off of the top of my head.
--
| Thread-Topic: Drilldown doesn't work on wildcard search!!!
| thread-index: AcTMqhu37sydctEqQ0aX2mQTQ1wFQA==| X-WBNR-Posting-Host: 193.212.219.1
| From: =?Utf-8?B?Si4gS2FuZG8gNDEx?= <JKando411@.discussions.microsoft.com>
| Subject: Drilldown doesn't work on wildcard search!!!
| Date: Wed, 17 Nov 2004 05:34:05 -0800
| Lines: 23
| Message-ID: <03E96D3C-A721-435D-881D-4AB818C8B6EB@.microsoft.com>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 8bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.sqlserver.reportingsvcs
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.1.29
| Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: cpmsftngxa10.phx.gbl microsoft.public.sqlserver.reportingsvcs:35151
| X-Tomcat-NG: microsoft.public.sqlserver.reportingsvcs
|
| I have a report parameter â'spare part numberâ' thatâ's configured
like this:
| Data type: string, non-queried (empty list), no default value. This field
is
| rendered as a text box in preview. I also have other parameters but these
are
| all based on queries and datasets and are therefore rendered as drop
downs.
|
| What I really want is the user to be able to ask for a report on many
spare
| part numbers in one go. I canâ't get this to work, so if you know how,
please
| let me know.
|
| What works is to leave this field empty and have a filter like:
| =Fields! PART_NR.Value Like =iif(trim( Parameters!SparePart.Value
| )="","*",Parameters!SparePart.Value )
|
| When I enter a valid spare part number (e.g.: 3215323) or do a wildcard
| search (e.g.: 32*) The correct result is shown, but my drilldown no
longer
| works. Clicking the â'+â' sends the report back to me collapsed (This
is in
| preview mode).
|
| Anyone know anything about this?
|
| Regards
| AK411
|
|