I'm using linq to sql to populate a list of objects. One of the fields I'm interested in is stored as a tinyint. How should I declare this property type in my object definition? As a Short? Byte? Int16?
I have this problem where I am passing NVARCHAR parameter to a stored procedure, and the field type in the table for that parameter is INT.
I am doing that because I am using IN function, and for example if I want to send multiple parameters, that is the only possible way to do through .NET. Or not? The SP doesn't get executed because of the wrong type, and I am trying to cast the value, but I get an error. Here is how I am trying: Example:
@Parameter nvarchar OrderStatusID = ('30, 40')
(o.OrderStatusID IN (CAST(@OrderStatusID as int)) OR @OrderStatusID IS NULL)
Is there a way to cast each value separately, or what will be the best way to cast whole value as INT.
i have a xml file and i am retrieving its value using Linq to xml and assigning it to ViewData.
[code]...
but foreach (var item in ViewData["Persons"] is giving type casting error..what should be the exact type csting so that i can retrive values in the format item.Fname.
The GenerateRowColumnDataTable method retrieves all form variables with <input> tags. My problem is that my columns are named in a strange format like this:
#X#_G1_NAME_1 so when I look at what's being rendered I see %23X%23_G1_NAME_1 so I thought I could use Server.URLEncode() around Request.Form but I'm getting an errot that it can't be converted to a string. What would you do in this case?
I have a bit column that is saved as 1 or 0 in the database. I want to check the value in the table and then do an if statement depending if its 1 or 0. How can I convert it to an int?
i had
lockValue = (int)sqlCommand1.ExecuteScalar();
I want to assign it to the lockValue int variable. I then want to go on and check
Why it's not possible to cast a SiteMapNodeCollection (eg. SiteMap.CurrentNode.ChildNodes) to an IEnumerable<SiteMapNode>? I was wanting to do some filtering of the collection via LINQ, but this might not be possible?
The MSDN page says it implements IList, ICollection, and IEnumerable, so I don't see what the problem is.
I have a situation where I'm iterating through all the controls on a form, specifically looking out for any of these three types of controls: Labels, TextBoxes, CheckBoxes
I can, of course, get the type of the control and then use a Switch-Case construct to cast labels as Labels, textboxes as TextBoxes, and checkboxes as CheckBoxes.
But I'm wondering if there's a way to do something with one or two lines of code to gain access to the Text property of each of these controls?
I am passed an IQueryable that might be already be ordered and that therefore might be an OrderedQueryable. I need to apply it a new ordering via reflection, anb before choosing if calling either OrderBy or ThenBy I need to now if the Queryable is IOrderedQueryable.
Now comes the problem! To see if may variable say query is an IOrderedQueryable I do:
IOrderedQueryable orderedQuery = query as IOrderedQueryable;
One might expect orderedQuery be null in case query is not an IOrderedQueryable ! INSTEAD orderedQuery is NEVER NULL. It takes the value of a different type!
I understand that this might happen because of deferred execution...
I tried also: query is IOrderedQueryable and it is always true!
How can I verify if query is actually an IOrderedQueryable before getting an exception when calling ThenBy?
The IQueryable comes from the Entity Framework 4.0
I am able to see it if I access the object that is behind the interface, but this way I would loose the benefif of using interface, and my class might not work with a different implementation of the IQueryable.
Im dynamically generating an HTML Select Box, lets call it myselect. Im creating this select box based on some database values Im generating an HTML Select Box.. almost like a string that Im just spitting out to the page. So it's never a control in the codebehind, just part of a string thats rendered as HTML by the browser. If I submit my form, and in my codebehind I perform:
Dim myVal as String = Request.Form("myselect")
That code will give me the VALUE of the myselect select box. How can I refer to this control to cast it as a System.Web.UI.HtmlControls.HtmlSelect control? Request.Form seems to give me the value, but I want to reference the object itself..
I'm using the default SqlMembershipProvider,but I've created a custom MembershipUser class (SoeMembershipUser) because I needed a "DisplayName" property.All the DisplayName does is look at the UserName and format it differently.When I try to cast a MembershipUser to a SoeMembershipUser user I get an InvalidCastException.
Exact error is: "Unable to cast object of type 'System.Web.Security.MembershipUser' to type 'Soe.Tracker.SoeMembershipUser'."
Here is the code that fails:
SoeMembershipUser user = (SoeMembershipUser)Membership.GetUser(username); // invalid cast
I have also tried casting later like so:
MembershipUser user = Membershipship.GetUser(username); // ok ... string displayName = ((SoeMembershipUser)user).DisplayName; // invalid cast
Here is the SoeMembershipUser class:
NOTE: I left off the constructors at first, but added them in later when I started having problems. Adding them made no difference.
public class SoeMembershipUser : MembershipUser { public SoeMembershipUser() : base()
I´m trying to use session to store a value (id). The problem is that I have to store it as a string. When trying to use the instance of the id I get the error:
Exception Details: System.InvalidCastException: Specified cast is not valid.
Source Error:
Line 156: Line 157: Nemanet_Navigation newFile = new Nemanet_Navigation(); Line 158: newFile.Nav_pID = (Guid)Session["id"]; Line 159: Line 160:
This is where I get the id and that seems to work fine. Session["id"] gets the value.
But I get a NullReferenceException. So I moved the label outside of the table and put it just inside the accordion. The same behavior occurs. Then I gave the accordion panel an ID and did FindControl there, but the same issue occurs.
I want to enable/disable controls of a asp.net page against a logged in user's permission. say 'admin' & 'hr' can change user's birth date text-box in a page but others will see the text-box as disabled.
I am trying to save the every date clicked in a List of Date using a session variable. I am getting a casting error ..."when casting a number the number must be less than infinity".
Okay, so I have a Generic IList of custom objects that I want to use as a datasource for a repeater.
[Code]....
In the WebForm inside the repeater, I place this code:
[Code]....
when I try to run it, I get the error "Unable to cast object of type 'System.Collections.Generic.List`1[MyCustomObject]' to type'MyCustomObject'. ". Which makes sense, really.
What's the best way round this? Is there any way I can get the direct cast working? I'm loath to have to create a custom list item that implements IBinding or something and bind that directly, as that'll mean a lot of legacy changes which may create further bugs. Or is there a better way?
i'm having a gridview with textboxes and i'm allowing user to enter all the textboxes and when submit button is clicked, I'm constructing the Object and adding all the rows to LIST class.,After that i'm putting that LIST elements in a session. Everything is fine, But when i try to cast the session object to LIST type and pass it to XML serialization, I cannot see the elements in the list and it is showing LIST as NULL. I can see the generated XML string with ROOT and my classname as attributes without no data.
I use the DetailsView control to display selected employee's data for HR. The list of data elements has gotten pretty long so I thought I'd put some tables & panels inside the ItemTemplate and EditTemplate. Testing with NO code behind in effect works perfectly on display & update. Now I need to manipulate some stuff in the code behind which requires me to cast the controls I'm after. However old cast code doesn't work (it says the row index doesn't exist).
First is a clip of the DetailsView which gives me 3 nice columns.
I am creating an Asp.net web site which will support dynamic data. When I am creating a dynamic web site from Scratch (from template in VS) all is working fine. But when I am trying to add dynamic entity (.edmx) file and running the application I am getting following error
"The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'. "
I have a scenario where i have to pass the array list to the WebService.
WebService:
[WebMethod] public void GetCommission(List<BOLibrary.Flight.DTContract> Loc) { CommissionManager test = new CommissionManager(); }
Client:
List<BOLibrary.Flight.DTContract> BoList = new List<BOLibrary.Flight.DTContract>(); BOLibrary.Flight.DTContract dtConboj = new BOLibrary.Flight.DTContract(); dtConboj.ValidatingCarrier = "AA"; DTContract[] loc1 = BoList .ToArray(); service.GetCommission(loc1);
when i am trying to do this i am getting the exception that cannot convert the BOLibrary.Flight.DTContract to DTContract This is because when webservice create proxey consider Type(DTContract) not namespace(BOLibrary.Flight.DTContract)and i have to pass the list or arraylist of BOLibrary.Flight.DTContract Type.
I am using the following code to convert any valid object, to a date time:
[Code]....
When i call this mehod from my web pages, using a blank("") value in TextBox.Text property as a parameter, the method is throwing an FormatException exception.
[Code]....
Ironically, the same method does not throw any exception with the same input when tried in a different machine.
Are there any regional setting that need to be modified in .NET 2.0 for this to work ?
P.S:
The method also works when called using a string variable, like