I want to show user details on User Profile using Session but it is not working any other way kindly suggest me, I’m using ASP.NET MVC. Login class: Dashboard controller: Screenshot of output: Answer When you use a session, that session is available throughout the site based on how long you have given it in the web config file. And
Tag: c#
get request to accepts params in postman, currently sends a unsupported media type error
I’ve built different get methods using body request to select an id (with raw json). However, as I learned that get methods doesn’t support body request, I would like to change so that I can use params in postman insted. However, when I do it now, I get an 415 Unsupported Media Type. Here’s the method: Controller: Interface class: Before
add sql WHERE statement to select new ID:s in database (asp / sql)
I’m trying to update a website where there’s new ID’s for different damage groups. All the new ID’s start after ID 139. In SQL the statement to get the new groups are simply: However, I want to implement the same statement in my ASP code and in the method that fetches the current damage groups. Here’s the current method for
Updating multiple rows for user – Setting 1 row as “Default” Yes, and other to be No
Lets assume the following data selected from SQL TBL_Profiles: No User Profile Default 1 User1 Profile1 Yes 2 User1 Profile2 No 3 User1 Profile3 No Currently, User1 default profile is Profile1. That’s how it was setup initially when profiles were created. If User1 decided at a later stage to change his/her default profile, that means the newly selected profile should
Returning a value before committing transaction and (UPDLOCK, HOLDLOCK)
I need to check if a record exists – if yes: then returns its id, if not: creates a new record and returns its id. I am using WITH (UPDLOCK, HOLDLOCK) in SELECT to prevent from duplicates (it creates lock). I wonder if I should commit the transaction if a record exists in a database for realising the lock? Answer
What is the proper way of selecting multiple scalars within the same “using” statement with Dapper?
I have wrote the following method, which I hoped to make the method run faster by executing the tasks in parallel: Unfortunately, I receive the following exception: System.InvalidOperationException: ‘BeginExecuteReader requires an open and available Connection. The connection’s current state is connecting.’ How should I implement it correctly? Answer First things first, executing many commands in parallel against a database will
Is there a way to SELECT a database table using a variable?
I tried this statement: string query = “SELECT question FROM ‘” + GlobalVariables.dbQCode + “‘ WHERE [question_code] = ‘” + GlobalVariables.questionCode + “‘ “; and when I run the code it is giving me an exception: Syntax error in query. Incomplete query clause. Is there a way where I can use my variable? I want it to work because I
Convert html foreach loop data to webgrid using asp.net mvc
Below html table is filling using two loop condition, and same i want using two loop conditions to fill Webgrid I have tried to fill one field in web grid by using below code. when I am click debugging mode after code line complete on this line the following error is showing. Answer The exceptions you’ve included in your question
SQL Filter by dateTime
day is a integer variable. If I set the day value to 1, database is filtering for 24 hours. But if I set the day value to 1, I only want to see the logs of the new day. How can I do that? Thank you for your help. Answer
ASP.NET Core display all rows in database on page
I am trying to display every row from a database on a website with ASP.NET Core MVC, but I cannot find any source on how to do it.. This is what Ive tried to do but I got stuck: My Database is structured like this: Id, Username, Password, PasswordHash, but I only want to display Username to begin with. If