C# - Route Constraint With Database Look Up?
Aug 24, 2010
I'm just starting out with C# and ASP.NET and have the following questions. I am working with code adapted from a couple different tutorials playing with Northwind and have gotten this far. The list of acceptable categories is currently hard coded in a string but I would like to look up the CategoryName in the database to verify that it exists.
Obviously the purpose of this is to ensure that users don't just type:
[URL] and return a valid page.
Also does anyone have an tips of how they are dealing with capitalization issues since the routing is case sensitive? For example Categories/beverages should forward to Categories/Beverages ?
[code]....
View 1 Replies
Similar Messages:
Sep 17, 2010
If I have a route mapped as follows, how can I add a constraint for the route values with periods in?
[Code]....
View 6 Replies
Feb 8, 2011
I'm attempting to find a way to preventing a user from accessing a specific xml file. I've tried doing...
route "SiteMap",
"SiteMap/siteMap.xml",
new { },
new { isLocal = new LocalHostRouteConstraint() });
[code]...
View 1 Replies
Oct 15, 2010
I am getting the following error The DELETE statement conflicted with the REFERENCE constraint "FK_Person_Country_CountryID_CountryID". The statement has been terminated. I do not want the user to delete the country if there are any FK contrains. Or a better way will be to ask the user if they want to delete the records referencing this "Country".
[Code]....
View 3 Replies
Mar 13, 2011
I tried to mix asp.net 4 webfrom and ASp.Net MVC 3. I add required lines in webconfig, but I've issues implementing route in global.asax
Currently I use several routes for webfroms. routs template are like below
routes.MapPageRoute("Node", _
"article/sport/{nID}/", _
"~/article/articleview.aspx")
I encounter error, when I add below lines to global.asax
routes.MapRoute( _
"Defaultss", _
"{controller}/{action}/{id}", _
New With {.controller = "Home", .action = "Index", .id = UrlParameter.Optional} _
)
I want to know how could I mix ASp.Net MVC routes with webforms routes.
View 3 Replies
Mar 9, 2010
when i run the app i got this error
A route named 'Admin_default' is already in the route collection. Route names must be unique.
Parameter name: name
this is my AdminAreaRegistration
[Code]....
View 2 Replies
Sep 24, 2010
I have a url that I want to map routing to:
[URL]
where tabvalue is one of: "personal", "professional", "values" or nothing.
I want to map it to a route like:
Member/Edit/{tab}
But my problem is - I don't know how to specify such constraints. I'm trying this regex:
^[personal|professional|values]{0,1}$
but it only works when I use url
[URL]
[URL]
and doesn't work for
[URL]
how to specify the correct constraint?
P.S. I'm not using MVC, just asp.net WebForms
View 6 Replies
Mar 14, 2011
Was looking at asp.net mvc complex routing for tree path as an example of how to define a custom route handler for my MVC app. Essentially, I want to give the end user ultimate flexibility in defining the URL for any given page, so I provide them with a field in the interface to specify their own custom URL.
My custom route handler is basically a wild-card handler. It will do a lookup and if it finds a match, map it accordingly. However, if no match is found, I want it to fall back and find the next rule that matches in the global.asax. Is that possible? Or do I essentially need to code the mappings that used to exist in my global.asax into my custom route handler?
View 2 Replies
Nov 23, 2010
I have a scenario, I will pass a StatusID , According to that StatusID , The rows will be fetched from a table[tblEventStatus] and newly fetched row has to fecth the data from another table [tblEvent].
Ex: StatusID - Value I am Passing
Table 1: tblEventStatus - Column:SysID - StatusId - EventID
Table 2: tblEvent - Column:SysID - EventID - EventDesc
I want to use the Linq - I tried like this, But It doesnt work
var query1 = from objtblEventStatus in db.tblEventStatus
where objtblEventStatus.StatusId== StatusId
join objev_events in db.tblEvent on objtblEventStatus.EventID equals
(objev_events == null ? null : objev_events.UID)
select new { Category = objev_events.EventID , Name = objev_events.EventDesc};
View 1 Replies
Mar 9, 2010
I have a table with three fields, User, City and Country, where exactly one of the fields must be non-NULL at all times. Can I use an SQL constraint for this or should I rethink what I'm doing?
The scenario is that my database should contain documents that can be attached to users, cities or countries. So a row in this table contains exactly one document for either a user, a city or a country. However, one should be able to search for all documents as well, regardless of what entity it has been "attached" to.
The reason I'm not using three different tables instead is that I want to avoid having to JOIN the three tables when searching for documents in all of the three places. I'm imagining that the kind of denormalization I'm attempting to use here will improve performance.
View 5 Replies
Feb 17, 2010
Suppose I have a user table that creates strong relationships (Enforce Foreign Key Constraint) with many additional tables. Such orders table ..If we try to delete a user with some orders then SqlException will arise.. How can I catch this exception and treat it properly?Is this strategy at all?1) first try the delete action if an exception Occur handel it?2) Or maybe before the delete action using code adapted to ensure that offspring records throughout the database and alert according to .. This piece of work So how to do it?
--Edit:The goal is not to delete the records from the db! the goal is to inform the user that this record has referencing records. do i need to let sql to execute the delete command and try to catch SqlException? And if so, how to detect that is REFERENCE constraint SqlException?Or - should I need to write some code that will detect if there are referencing records before the delete command. The last approach give me more but its a lot of pain to implement this kind of verification to each entity..
View 1 Replies
Mar 1, 2011
My attendance table structure as follow
EmplID AttendanceDate Atten_Type Atten_Taken
it mean it has lot od data like below with differnet dates
E1
2011-02-21 00:00:00 CL
1
E2
2011-02-21 00:00:00 P
E1
2011-02-22 00:00:00 CL
E2
2011-02-22 00:00:00 P
E1
2011-02-23 00:00:00 CL
[code]...
View 8 Replies
Jul 20, 2010
I have a custom constraint that queries a value against a repository. Is it possible to replicate the dependency injection available to controller constructors?
View 1 Replies
Jun 22, 2010
I have a message table that self joins to itself where Message.ID == Message.Parent. So I have 1 Message with several ChildMessages. This is set up nicely with a Navigation property.
The code is currently:
var message = from m in soe.Messages.Include("ChildMessages")
where m.ID == id
&& m.IsActive
select m;
return message.FirstOrDefault();
What I really want is to only return 1 Message (that is equal to a particular ID and isActive) with all of its Active ChildMessages and I want to do it in one call to the database.
View 2 Replies
Jun 4, 2010
I want to create a constraint for 3 columns (A B and C) where if columns B or C are not null, then A cannot be null. And vice versa (i.e., if A is not null, then either B cannot be null, or C cannot be null).I am not very well versed in SQL and would like to know what is the best way to achieve this (e.,g Check constraint, stored procedure, function, trigger)? I'm leaning towards trigger but I'm not 100% sure if that's right nor of how to implement it.
View 3 Replies
Jan 6, 2010
Here I have specified a query which gives an idea about how to drop a constraint and recrate it..
[Code]....
Parent_TableName: is the name of the table where we actually reffer.
View 1 Replies
Jan 8, 2011
The UPDATE statement conflicted with the FOREIGN KEY constraint "FK__Software__Packag__5165187F". The conflict occurred in database "StudentDB", table "dbo.Package", column 'PackageID'. The statement has been terminated.
what i try to do is run this;
[code]....
View 4 Replies
Apr 24, 2010
let say i have 2 table (PARENT and STUDENT table)
the structure for both table are
STUDENT
PARENT
student_id (PK) parent_id (PK)
student_parent (FK) parent_status (the value is either ACTIVE OR INACTIVE)
- parent_id is refer by STUDENT table as a foreign key
- now i want to inactive the status for parent
- i want my system pop out a message something like "The parent you want to inactive is refer by a student, inactive is not allow"
- is it any constraint in SQL Server 2005 to help me check whether parent it is refer by student table? The concept i want to use is something like delete constraint in SQL Server 2005 mean it is not allow to delete a person who is refer by a student in STUDENT table.
View 9 Replies
Nov 22, 2010
I'd really like to know how to do the same thing in my code as going into sql server management studio, clicking on the design of a table, and then from the file menu scrolling to the relationships and disabling the foreign key constraint by selecting no to the 'enforce foreign key constraint'.
View 2 Replies
Oct 30, 2010
I am creating a multi language website with asp.net mvc 2.0
I tried to solve the problem with routes and I guess it will work just fine but I need some constraint inside my route;
here is my routes;
I have two routes;
[Code]....
in 1st route, I do not need the language so it will pass without language. I am only excepting integer on this route as you could see on the id constraint.
what I need is that;
in the 2nd route, I need a constraint that specify language variable only can be en or tr. how can I write that?
View 6 Replies
Dec 6, 2010
i have a bizar situation, i have a SSIS package which imports records from a flatfile.First i get rid of all the double records, so I keep only unique records before I put them into the desired table.I have put a dataviewer on the flow and notice that there are no duplicate records, and though the SSIS package fails with a violoation of a promary key constraint.Hs anyone seen this before? It is really strange.
View 1 Replies
Feb 22, 2012
I'm working on an application using a 3 tier architecture and I'm having issues with a business layer select method. Basically, I have a gridview control that is populated by an objectDataSource. The ObjectDataSource calls a select method in the my business logic layer to retrieve data. When the business logic layer calls a table adapter method, I receive the following error message:
Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints
This is my first attempt at a 3 tier design and I'm not sure where to start with the debugging process.
Also, the stored procedure that is used by the table adapter select method, creates a new column inside of the query. This column is not included in the datasets datatable. I manually inserted a new column into the datatable from the dataset designer. The new column was created to store the values that are being returned from the new column in the stored procedure. I'm not sure if this is the correct way to do this or not but it allowed me to access the column in the business logic layer methods.
View 1 Replies
Aug 25, 2010
Is it possible to allow repeated nulls on a column with a unique constraint? This column will won't always be populated with data upon insert, a condition must be met before the value is update. Once updated, it needs to be unique. Do I need to assign a temporary, random value or
View 1 Replies
Feb 15, 2011
When I get an exception message like this I want an Exception Class name to compare.Not wantto compare a string to match with substring.when I get an unique constraint error like this below how can I control if error exception type is exactly sqlserver unique constraint error ?:
catch (Exception ex)
{ if (ex.class==SQLUniqueException) blahblah();
};
View 2 Replies
Mar 23, 2011
had a data table in which i made one column as primary key..the data table is binded to stored proc output..now the datatable is not allowing same values for primary key column,functionality is fine..but the exception is not raised ..simply row is not getting added to grid view..but i want an exception to be raised..how to do that??
View 1 Replies