In my C# project, I have a dictionary, its values are currently static. Now I need to set to its values in dynamically. how can I do that? I have an Oracle DB table called “country” there have two columns called, ID and CountryName as follows, How can I set this table values to my dictionary? Thanks in advance. Answer
Tag: c#
Multiple joins in SQL statement
To clear things up, I have two tables, employees and jobs. In employees I have columns firstname, lastname, employees id. In jobs I have columns job_id, job_name, job_description, job_opener, …
Dapper query with dynamic list of filters
I have a c# mvc app using Dapper. There is a list table page which has several optional filters (as well as paging). A user can select (or not) any of several (about 8 right now but could grow) filters, each with a drop down for a from value and to value. So, for example, a user could select category
How to join multiple WHERE clauses together in SqlKata?
I am using SqlKata to creating dynamic SQL queries. I have a list of conditions, stored in my database, which are generated according to my business rules. this is my code sample: var list = new List&…
Correct use of Try Catch for the SQL connection in C#
Is this code correct in means of Try/Catch? I need to value whether the action is done or not to inform the user about the result, so I will then get the bool value to know if connection was successful. Answer Your method can actually have 3 outcomes: The table was created successfully (method returns true) The table already exists
LINQ Room id where user exists
I have two tables: ChatRoom Id (int) ChatUser (where i insert the users to the chat room, 1 row per user) RoomId (int) // Id from table ChatRoom UserId (int) I want to loop out all rooms where im in i do like this. But how do get the room id where the second user with the variable userId2 exists?
Execute SQL command in Entity Framework Core 2.0 to delete all data in a table
I want to execute an SQL command from Entity Framework Core 2.0, but I can’t figure out how to do so. 1.- The reason why I need to, is that I want to delete all data from a database table, and using Context.remove or Context.removeRange would produce many calls to DB (one for each data in the table). 2.- I’ve
InvalidOperationException: No columns were selected when performing a DELETE query
I have the feeling I’m missing something obvious, but I can’t quite put my finger on it. So when this piece of code gets executed, I get the exception: Even though I don’t need anything back from my call. I just want to know whether or not my DELETE query has succeeded. The strange part is that the query does
Entity Framework Core “The entity type ‘XXX’ requires a primary key to be defined.”
So I’m currently trying to create a code first migration with Entity Framework Core for a table that displays which lectures the application user has completed. My model looks like this: public class …
How to extract date time from sql and bind it to datetimePicker
I have saved dates from datetimepicker to sql in my windows form app with the format (dd-MM-yyyy). To edit date, I want to first fetch saved date and show in the datetimepicker control. Like if 28-03-…