I have a situation where I have a crystal report where I pass in a start and end date via rdoc.SetParameterValue this works fine, except that, I do not want it to show a date if I pass nothing for the date variable, I just want it to be blank
To an attempt to do so i have written
if (DateStart != defaultDate)
{
rdoc.SetParameterValue("DStart", DateStart);
}else
{
rdoc.SetParameterValue("DStart", "");
}
Which gives me the error The types of the parameter field and parameter field current values are not compatible of course, this makes sense because I am trying to set a date to a string variable.
However, I am unable to think of a solution, nor do I see any solution in the Parameter's menu.
Appreciate it if I be given some assistance to solve this.
Regards
You may change the parameter type to string and pass the date as string:
DateStart.ToString()
I don't like this solution, but it works. Usually i just require the date.
Related
I tried to use
sqlDr.GetValue(a).ToString()
to display a DATE column from my database which looks like this..(the Date Submitted column)
But the problem is , when i display it using getValue(8).toString(), something like this is displayed..
Thanks for taking your time to read my post , any reply is much appreciated!
The problem is .Net does not have a Date-only primitive type. Therefore the Sql Server Date column type maps to a full DateTime value in .Net, which always includes a time component. If you don't provide a time component, the DateTime struct will have a 0-value time component, which maps to 12:00:00.000 AM.
To get around this, you need to specify the output format for your column, so that it explicitly does not include a time value. You want something like this:
((DateTime)getValue(8)).ToString("d")
However, the exact code you need will vary wildly depending on how your result table is created. If necessary, check the SqlDataReader.GetDataTypeName() function to know what type you're dealing with.
Try using the DateTime.ToShortTimeString Method ():
Console.WriteLine("Short date string: \"{0}\"\n", myDateTime.ToShortDateString());
Output: Short date string: "5/16/2001"
I have a problem with rendering report with correct parameter.
We have RDL report that has date parameter with default value which is an expression "=today()".
In project i have the following code in c#
for(int i = 0; i < 15; i++)
{
serverReport.SetParameters(new ReportParameter("dt1",date.ToString()));
File.WriteAllBytes(path, serverReport.Render("PDF"));
}
For first iteration sql stored procedure is called with the default parameter and following iterations are called with passed date(i checked it with sql profiler).
I want to mension that in loop i have many other reports with exact same default date parameter but the problem is with this one. I have compared all parameter properties in 2 repors(one that works and the other that is not working properly), but they are identical. I cant find any difference.
If i delete default value "=today()" then report is working fine.
Maybe sameone had similar problem and recommend me something about this. Thanks in advance.
A few things to check:
SetParameters takes IEnumerable<ReportParameter> not a single ReportParameter object. Call it like this instead:
serverReport.SetParameters(new ReportParameter[] { ReportParameter("dt1", date.ToString()) } );
Make sure that the parameter does not have the available values filled in as well as the default value. If the date passed is not one of the valid values (if applied) it won't work. For example, if the available values are set to =Today then the only report that will run properly is the first one that coincidentally uses that value.
Are you sure that date.ToString() is passing an appropriate and valid date?
Does the server's report parameter match the development environment? Parameter settings aren't automatically updated so that any modifications made on the server aren't overwritten by deploying the report again. Check the server's report parameters and update if necessary, or simply delete and redeploy the report.
Try to completely remove the not working report within the server (and to test,also one of the working) and re-deploy both to the server. you could also check in reporting manager for the parameter settings, because there the difference might be visible.
I had that kind of issues before with report parameters and know that the parameter settings are not overwritten correctly all the time you deploy the report.
How can I make a parameter in reportviewer as optional, so that if the parameter is empty or null then it is ignored and the report should not apply filter on it?
First you need to ensure that the parameter is nullable within SQL Server Report Builder. Double click on the parameter in question and select the Allow null value.
I would post an image but I do not have enough blah...
The final thing to make it work is to pass a null value to your report... This can be done in different ways, but this is how I was using it...
ReportViewer1.ServerReport.SetParameters(new ReportParameter(tb.ID, new string[] { null }));
Hopefully this helps.
I am working on c# project and using winform.
Here the problem is the query was working previously but now it is not working
Here the todaydate is a datetimePicker which is set to short date format
and my datatype of column is smalldatetime the error i am getting is
The conversion of a nvarchar data type to a
smalldatetime data type resulted in an out-of-range value.
The statement has been terminated.
if i have two date time picker one for date and second for time then how can i insert? please can you guide me
AddWithValue determines the datatype of the parameter from the value you pass.
In your case you are passing a string and thus the parameter is passed to the database as a string not as a datetime expected by the database
you should change that line
cmd.Parameters.AddWithValue("#today", todaydate.Value);
You're currently passing in the text value, which means something else is having to then parse it as a date. Don't do that. Given that you've got a DateTimePicker, you should just use the DateTime value it provides:
cmd.Parameters.AddWithValue("#today", todaydate.Value);
... or create the parameter first with a specific type (SqlDbType.SmallDateTime), then set the value using todaydate.Value. The important point is to avoid the string conversion.
Wherever possible, you should avoid converting values into text. Keep them in their "natural" form (e.g. DateTime in this case) for as much of the time as possible: on input, parse into the natural form, and if you can avoid ever converting to a string, do so!
I think your time7 column in database is smalldatetime and you tried to assign it a string. I don't suggest it.
Try with Add() method like this;
command.Parameters.Add("#today", SqlDbType.SmallDatetime);
command.Parameters["#today"].Value = todaydate.Value;
or you can use AddWithValue() as also like this;
cmd.Parameters.AddWithValue("#today", todaydate.Value);
I am very new to SSRS.
I have added one Parameter named Date on SQL Server Report
i have set parameter value from aspx.cs code behind file
i have drown that parameter on ReportHeader and i want display CurrentDate value on that parameter
and i tried =Join(Parameters!Date.Value,", ") but it displays #Error at runtime.
i also tried =Join(Parameters!Date.Label,", ") but it displays Nothing.
Please tell me how to display Parameter value on Report?
Not sure I understand what you are asking. To display the parameter value on the report, create a textbox on the report and then set it's expression to your parametername.value.
Something like this:
=Parameters!Date.Value(0)
Not sure what ur asking ...wheather u need report run date or parameter passing date ....
If u need report date .... follow this
Drag a textbox onto the report ...page header or footer
and ----> =Today()
If u need parameter value(date) what ur passing
Just the parameters!paraame.value ...
If I'm understanding your correctly you want to do:
=Parameters!Date.Value & ", "
& is the string concatentation operator in SSRS, you must have a space on each side of it FYI