ASP.NET DetailsView Update exception handling - truncated data - asp.net

I'm using a DetailsView for updating a record. If the edit input of some fields is too long, the system produces a "data will be truncated" exception.
I can see where I can detect the error in DetailsViewItemUpdating or DetailsViewItemUpdated, and provide a user message. However, I believe the visual feedback should be sufficient for this release, i.e. "hey, it didn't take my 30 characters, even though the header label said it would only allow 20".
Is there a way to force the DetailsView to do the truncation and accept the update?
Or some other approach to this data handling exception, which must be pretty common.

ANSWER: from Ammar Gaffar at EE:
Convert to template field
In EditItemTemplate
Set DataBindings > MaxLength property to desired max length of field
Works fine.

Related

SSRS - Pass Multi Value Parameter with Available Values Option Enabled Through Querystring

I have one Parameter on my report, that has multi value on.
And it's values came from a Dataset.
On my application, when I request a report, this parameter goes as an Querystring value. But when I use the multi value option, the parameter is not a single value anymore, but an "array" with multiple values (Of Couse).
REPORT?codArea=&codDiretoria=17&ultimaAlteracao=on&formato=PDF&codListaPrioridade=8&codListaPrioridade=13
Important Part:
(codListaPrioridade=8&codListaPrioridade = 13)
The issue, is the "Available Values" option. The Parameter having an Array as a value, don't have any of the "Available Values" and SSRS throw a error.
Important Part:
System.ServiceModel.FaultException: This report requires a default or user-defined value for the report parameter 'codListaPrioridade'. To run or subscribe to this report, you must provide a parameter value.
If i disable the "Available Values" option, i can send this "array" without any issue:
codArea=&codDiretoria=17&ultimaAlteracao=on&codListaPrioridade=9&codListaPrioridade=13&formato=PDF
Important Part:
(codListaPrioridade=9&codListaPrioridade=13)
="----> "& Join(Parameters!codListaPrioridade.Value, ",")
The trick is that I need create in this report, this parameter with "Available Values" enabled, but this parameter need to accept "Any" values (Because the Array that is coming on querystring).
The "Available Values" must be used to show which values are available only (Inside my application).
Inside SSRS, the parameter works fine, the issue only occurs when using this report in my application, sending the parameters values in a querystring.
The key part of the error is "This report requires a default or user defined value for the report parameter."
You don't need a default parameter. It sounds to me like your application is passing an invalid parameter value to the report. The reason it works when you disable the available values is because then it will accept ANY value at all.
Run the query that populates the available values and keep it open.
Set a breakpoint in your ASP.NET code just before it passes the values to the report server. Examine what those values are and make sure it isn't trying to pass anything that ISN'T in the list of available values you got from running the query.
If there is something different then that is the cause of your error. I can't remember off the top of my head if casing matters so you'll want to check that too. And if you check them and everything is fine... check them again. I don't know how many times I've thought there wasn't any data out of place only to suddenly see it later.
An alternate theory would be that you just aren't passing the multi-value parameter to the report server correctly. I've never tried to do it directly in the URL before but on the MSDN page Pass a Report Parameter Within a URL in the "other examples" section it shows passing a multi-value parameter. In their example they seem to append a number to the end of the parameter name for each value. But I'm not sure if that is right either.
https://myserver/Reportserver?/SQL+Server+User+Education+Team/_ContentTeams/folder123/team+project+report&teamgrouping2=xgroup&teamgrouping1=ygroup&OrderID=747&OrderID=787&OrderID=12
But since you're already writing .NET code let me make a suggestion. Use the webservice as a webservice. It makes things like this so much easier. You just add the web service as a reference to the project and then basically call it like any other .NET class. The reference reads the WSDL file and shows you all of the available API calls and their parameters and what you'll get back. It really is quite a nice feature. Check out this MSDN article on "How to: Add a Reference to a Web Service" and then this TechNet dev guide: https://technet.microsoft.com/en-us/library/bb522713.aspx

SQLDataSource parameter insertion: Sanitisation and formatting

I am building a Web application and I want to allow users to insert records into a database. The method that I came across is to take the information from text boxes and run this code:
SqlDataSource1.InsertParameters["ProductCode"].DefaultValue = txtProductCode.Text;
SqlDataSource1.InsertParameters["Name"].DefaultValue = txtName.Text;
SqlDataSource1.InsertParameters["Version"].DefaultValue = txtVersion.Text;
SqlDataSource1.InsertParameters["ReleaseDate"].DefaultValue = txtReleaseDate.Text;
try
{
SQLDataSource1.Insert();
}
...
If I try to inject some SQL I get the error message:
Message: String or binary data would be truncated. The statement has been terminated.
Does this method sanitise the parameters? I am having a hard time finding this information because I am not sure if there is still a way to get around this error. If it does not how should I go about sanitising the inputs?
Additionally, the ReleaseDate parameter seems to be currently reading as dd/MM/yyyy but is there a way to lock this so that the same code on a different system doesn't behave differently. I am worried that if the code is run on a system with different regional settings it will use a different format.
One of your field in the table is not long enough to insert the value. You need to check each of ProductionCode, name, Version and ReleaseDate for their length and increase them accordingly.
http://msdn.microsoft.com/en-us/library/aa196741(v=sql.80).aspx

ASP.NET ReportViewer Parameter Prompt doesn't show

I've been looking for this answer for a couple days now and I've been getting little bits of information that make it seem that you can have ReportViewer Control automatically prompt for the report's parameters. Just everything that I've tried and found doesn't seem to work. I've gotten the Parameter Prompts to work on a Windows Form but I just cannot get it to work in ASP.NET
I guess I'm simply asking can you get Report-viewer's Parameter Prompts to work in ASP.NET? if so, How?
I know you can do it manually, it's just, I feel if you can make ReportViewer Prompt automatically why program it yourself?
Edit: this is for local processing btw.
Prompting for parameters is not supported in local processing mode.
In article Report Parameters Dialog Box (Visual Studio Report Designer), which is invoked by clicking the Help button on that dialog, it says in the introductory text that:
The parameters properties that you specify in the Report Parameters
dialog box become part of the report definition. Some properties are
intended for programmatic use only. In contrast with reports that are
processed on a remote report server, a locally processed report does
not have a parameter input area used for selecting or typing parameter
values.
A little testing shows me that the default values specified for the parameters will be used, unless you modify them programmatically. I could not find an explanation on this design decision. If you want to use local processing, and prompt for user input, I would recommend to follow this solution:
I you embed the reports in a ReportViewer Control, you can put it on a page or form and add custom input controls to that page or form to gather report parameters. In the code-behind files, you will then pass the parameter values using code like this:
List<ReportParameter> parameterList = new List<ReportParameter>();
List<string> selectedProductTypes = listboxProductTypes.GetSelectedValues();
ReportParameter productTypes = new ReportParameter("ProductTypes", selectedProductTypes.ToArray(), false);
ReportParameter username = new ReportParameter("Username", "<current user>", false);
parameterList.Add(productTypes);
parameterList.Add(username);
reportViewer.LocalReport.SetParameters(parameterList);
In this example, you can see how to pass a multi-valued parameter, the values of which are taken from a multi-select ListBox.
You can also create a page that has the controls to gather the parameter input, put them in a set session variables and then transfer to the page that has the report viewer.
use object data source and set the parameter source as Session.
The only code you need to write is filling the session variables.

SqlDataSource erroring when retrieving NVARCHAR(max) column

I'm writing a small ASP .Net application in order to retrieve data from a SQL database. The application uses drop downs in order to select what the next drop down should contain and when a page is selected, it should retrieve the HTML from the database. Everything is working until it gets to the retrival of the HTML data. When I try to retrieve the data, I get:
Microsoft JScript runtime error:
Sys.WebForms.PageRequestManagerServerErrorException:
An unknown error occurred while
processing the request on the server.
The status code returned from the
server was: 500
The HTML column is a defined as NVARCHAR(MAX), but I can't see this causing a problem. The application works if I set the DataValueField to another column. Has one else come across a problem like this? Maybe someone could shine some light on this?
One thing I noted when dealing with varchar(max) columns is that the framework still commonly expects to have a size associated with it. What I ended up having to do was specify the length as -1 to get it to accept a varchar(max) field. Your error message doesn't indicate that this is the problem, but you might try experimenting with it rather than turning off the validation, which could possibly have other repercussions.
Figured it out. Just needed to set ValidateRequest to false at the Page level.

Find non server control attribute value in postback?

I can get the value of non server control with Request.Form["fieldID"];
how i can get the attributes of these control?
some think like these :
Request.Form["fieldID"].Attribute["the_Attribute"].value;
or any other way
You're able to get the fieldId because its value is included in the POST, its attributes however will not be.
I'd recommend using something like firebug or fiddler to see the info that's coming in on the request, or even using the locals or immediate window to explore the Request.Form object to get a feel for what you can/can't do in this kind of situation.
There are no attributes. The only thing sent in the form data to the server is the value from the form field.

Resources