Posts by Thiago Loureiro • 2,465 points
113 posts
-
1
votes2
answers674
viewsA: Do I need to use Visual Studio to program in C#?
Complementing Maniero’s response, there is really no need for an IDE to program, with . NET Core for example you can program with the notepad (going in the example more "Roots"), for example: dotnet…
-
1
votes1
answer409
viewsA: Search in a string with wildcards
In VB you have the Likeoperator, but in C# you need to do something customized, the solution is to create a Extension Method I found this example here, tested and worked. internal static class…
c#answered Thiago Loureiro 2,465 -
1
votes2
answers193
viewsA: Timeout Sql Server in a request via Web Api
Watching your code not found where you close the connection after running, quickly you can resolve by placing a con. Close() at Finally, see if this solves your problem. I recommend changing your…
-
1
votes2
answers95
viewsA: Doubts with the use of IF / ELSE in C
You have two options, one would be to make a Toupper and compare only with’M' instead of m or M the second option is as follows:: if ((sexo == 'm' || sexo == 'M') && idade < 20) It would…
-
4
votes1
answer214
viewsA: Resize image in c#
Hello, you can do it this way: There in your code you call this method, for example: var retImage = resizeImage(800, 600, dataImage.FileName); Resize method: public Image resizeImage(int newWidth,…
c#answered Thiago Loureiro 2,465 -
2
votes2
answers100
viewsA: Doubt with the language C#
You can do it this way, make sure that’s what you need. string palavra = "palavra"; string nova_palavra = ""; foreach (var c in palavra) { nova_palavra += c + " "; } nova_palavra =…
c#answered Thiago Loureiro 2,465 -
3
votes2
answers271
viewsA: Dapper requires writing SQL code, why?
Complementing Maniero’s answer, your code is dangerous because you are concatenating the values into the string and are subject to an SQL Injection. Here’s a simple example of Insert with Dapper //…
-
1
votes2
answers885
viewsA: Send email via c#
I use a free service (up to a certain limit of emails, but it’s high!) called Sendgrid (using Sendgrid’s Nuget). * I’m not advertising , I just like and recommend the service, it helps me a lot. And…
-
0
votes1
answer27
viewsA: datagridview does not fill the fields (Windows Form) - C# - Visual Studio Comunnity 2015
Its code has several problems, first of which is what Rovann quoted, the clear of the quantity field before being used. Second if you have any problem in your code the connection will not be closed…
c#answered Thiago Loureiro 2,465 -
2
votes2
answers784
viewsA: Vowel in full name C#
It has a simpler form, plays the return of Readline in a string and then counts with Linq using System; using System.Linq; namespace ConsoleApp1 { internal class Program { private static void…
c#answered Thiago Loureiro 2,465 -
0
votes1
answer464
viewsQ: Begin Transaction and Save Transaction SQL Server
I have a Storedprocedure on a system I’m working on and I have the following code begin transaction; save transaction Integration_SP; -- CODIGO commit transaction; I have been searching and only…
-
0
votes1
answer191
viewsA: Alternative C# Windows Service
For what described the best for your scenario is you use an AWS, Azure or similar, I do not know how critical/ size of your system, but I would flee from these "xxxHost" hostels of life. You can…
-
1
votes1
answer32
viewsA: SQL error in casting int to string
There is nothing wrong with your code, I replicated it and it works normally (check the print). Your problem is in your Query, already tried to play your query in the database ? DECLARE @Nome_STOR…
-
0
votes1
answer23
viewsA: Validation of all Text Boxes
Add a condition to your Lambda if (this.Controls.OfType<TextBox>().Any(f => f.Name != "txtCodCadastro" && string.IsNullOrEmpty(f.Text))) { MessageBox.Show("É necessario preencher…
c#answered Thiago Loureiro 2,465 -
1
votes2
answers703
viewsA: quote and quotes in a string (leaving " or #39; in the View)
Do it that way : string TextoComplicado = ",{\r\n\"@type\": \"ListItem\",\r\n\"position\": 2,\r\n\"item\": {\r\n\"@id\": \"http://www.enderecosite.com\",\r\n\"name\": \"descrição…
-
0
votes1
answer143
viewsA: Call AXIS service with C#
Otavio, First in your project go to References, Add Service Reference Click on Advanced click on Add Web Reference Enter the url and choose a friendly name for your reference: I made it to the list:…
-
9
votes2
answers1801
viewsQ: Async/Await with threads (C# 7.2)
I have this code and as you can see I created two examples, Parallel and Notparallel. I expected both to return me 3000ms, because both should run async (2000 and 3000) and the total time would be…
-
1
votes1
answer100
viewsA: Difference between a master page and web form
Masterpage as its name says is a Master page, used as a basis for other Webforms, for example, you can create Webforms with or without master page, if you select with Masterpage the new Webform will…
-
2
votes1
answer59
viewsA: Does the "sudo" command work in Debian?
Usually sudo is already installed, if you are not trying: apt-get install sudo -y but first you need to be as root, then: su - Also check if you don’t have sudo here: /usr/bin/sudo…
-
1
votes1
answer909
viewsA: How to map the return of a Value Object with Dapper?
It’s simple Edit, I did without the relationship the way you said: List<User> ret; using (var db = new SqlConnection(connstring)) { var sql = "select UserId, Name, Password, Email as Address…
-
0
votes1
answer65
viewsA: How do I treat message with special characters
You can work with Encoding, make sure it solves your problem: var buffer = await response.Content.ReadAsBufferAsync(); var byteArray = buffer.ToArray(); var responseString =…
-
4
votes2
answers152
viewsA: Treat Exception by code
You can use the command: int code = System.Runtime.InteropServices.Marshal.GetExceptionCode(); It will return the Exception code you seek
-
2
votes2
answers100
viewsA: SRP- Principle of Single Liability
SRP - Principle of Single Liability Single Responsibility Principle (SRP), or, Single Responsibility Principle. This principle says that classes must be cohesive, that is, have a single…
-
1
votes1
answer43
viewsA: Combobox Visual Studio Csharp
How popular the combobox: private void FillCombo() { var dirs = Directory.GetDirectories(@"C:\temp"); var files = Directory.GetFiles(@"C:\test2", "*.exe"); foreach (var t in dirs) {…
-
0
votes1
answer38
viewsA: Build problems with Postsharp in Appveyor
Solved, the solution is to add before Build a Key in the Registry: REG ADD "HKEY_CURRENT_USER\Software\SharpCrafters\PostSharp 3" /v LicenseKey /t REG_SZ /d <your_license>…
-
4
votes3
answers221
viewsQ: List<> Best practice, start with fixed capacity or start without limit?
I have a scenario where I will receive a list, or an array, or any other type of data from the database where I can know the size of my list before creating it, what is the advantage between the…
-
14
votes3
answers285
viewsQ: What is the function of #if false in C#?
I’m working on a project and I saw blocks of code with this #if false: What’s the difference to it (commented vs #if false) ?…
c#asked Thiago Loureiro 2,465 -
2
votes1
answer2592
viewsA: Error converting Base64 to String
It happens because in converting to Base64 sometimes characters change from + and / for - and _ http://en.wikipedia.org/wiki/Base64#Implementations_and_history Follows example working…
c#answered Thiago Loureiro 2,465 -
0
votes1
answer25
viewsA: Attach from a Classlibrary to an External application (Visual Studio)
After some researches I decided to create a Helper for this What I did was create a new application called Debuggerhelper, this application runs my main process and automatically attaches to it. So…
-
0
votes1
answer25
viewsQ: Attach from a Classlibrary to an External application (Visual Studio)
I have a project that is a Classlibrary and this DLL runs inside a Console Application, I have a requirement here where the developers of this Classlibrary need to debug this DLL with the…
-
1
votes5
answers371
viewsA: Validate model before inserting in the database
There is a nice way to validate the model without getting too dirty the code: Create a class called Modelstatevalidationactionfilterattribute.Cs public class…
-
1
votes1
answer158
viewsA: Nuget - Packages.Config using latest versions of packages
I have resolved as follows: I converted the Packages.config for packagereferences I used this Xtension to help me migrate:…
-
2
votes1
answer158
viewsQ: Nuget - Packages.Config using latest versions of packages
Setting I have a project where my Libraries (other components of the project) are Nuget packages, and whenever there is an update, a new version is generated in Proget.. and all developers have to…
-
0
votes2
answers1405
viewsA: Add a checkbox column to the datagridview
To Insert, use Datagridviewcheckboxcolumn: var col = new DataGridViewCheckBoxColumn(); col.Name = "Coluna" col.HeaderText = "Titulo"; col.FalseValue = "0"; col.TrueValue = "1"; //Make the default…
-
2
votes2
answers2197
viewsQ: What is the most efficient way to clear a list (List) with C#?
I have a scenario here where I create a list to check some items, and I need to clear this list inside the loop, and I got some questions regarding the performance I must check the list before I…
-
1
votes1
answer221
viewsA: Block typing Textbox field with Calendarextender
You have some options, you can use the ReadOnly="true" <asp:TextBox ID="txtDate" runat="server" ReadOnly="True"></asp:TextBox> or txtDate.Attributes.Add("readOnly", "readonly"); or via…
-
0
votes1
answer71
viewsA: limit users in the database
Your code solves the problem, but I would do otherwise, if any problem occurs the connection will stay open, and is not doing close and Dispose objects correctly: int count; using (SqlConnection con…
-
2
votes1
answer41
viewsA: What is the property of a COM+ component "Remote Server Name"
According to Microsoft documentation https://msdn.microsoft.com/en-us/library/windows/desktop/ms686107(v=vs.85). aspx#applicationproxyservername What you need is Applicationproxyservername…
c#answered Thiago Loureiro 2,465 -
2
votes1
answer1032
viewsA: Dependency Injection in . NET Core
After researches I found an interesting material, following examples: We can inject dependency into . NET Core as follows: public void ConfigureServices(IServiceCollection services) {…
-
4
votes1
answer419
viewsA: How to list containers in Docker?
You can do it this way: CONTAINER_NAME='mycontainername' CID=$(docker ps -q -f status=running -f name=^/${CONTAINER_NAME}$) if [ ! "${CID}" ]; then echo "Container doesn't exist" fi unset CID or if…
-
1
votes1
answer687
viewsA: Exchange "Web Browser" Vb.net
You have some options, one of them is what Rovann quoted, so I’ve researched it’s worth testing on Gecko, it’s based on Mozilla. I’ll put a C# code sample (for Vb.net you won’t have trouble…
-
0
votes1
answer42
viewsA: Console validator
Your question is a little wide, but I’ll put an example here for you of how to read this file and get exactly the piece you need. public void ReadFile() { string line; using (StreamReader reader =…
-
1
votes2
answers402
viewsA: Sending information between PC (Windows Form, C#) and Android
The best solution is for you to expose an API (may be in your Forms application) so you can use the Nancyfx, or create an API project separately. In this API you will have Endpoints and by the…
-
0
votes1
answer364
viewsA: Problems with Findsystemtimezonebyid in Web.API . NET Core in Docker (Linux)
Going back in time a little remembered that Linux has Timezone nomenclature different from Windows In Windows we have for example Eastern Standard Time On Linux we have America/New_york I found it…
-
0
votes1
answer364
viewsQ: Problems with Findsystemtimezonebyid in Web.API . NET Core in Docker (Linux)
Setting: I am migrating a Webapi to . NET Core, on Windows is running normally. Problem When I am running on Docker (Linux) (Docker-Compose) I am having the following problem: "The time zone ID 'W.…
-
2
votes2
answers262
viewsA: How to use Simpleinjector in a multi-layer project?
Complementing Lunardi’s response, and looking from another perspective: Create an Infrastructure project and relate dependencies (this is the "Wiring" point of your DI); Create a Core project, has…
-
0
votes1
answer63
viewsA: Help on Printpage in c#
I imagine you’re wearing the Printdocument. PrintDocument printDoc = new PrintDocument(); printDoc.PrintPage += new PrintPageEventHandler(printDoc_PrintPage); Then add the Graphics there: Graphics g…
-
2
votes1
answer677
viewsA: Permission Sql Server User
You create the user and in Server Roles you arrow the permissions. It is also possible to map the user directly to a DB in the User Mapping menu. Details about Server Roles:…
sql-serveranswered Thiago Loureiro 2,465 -
0
votes1
answer700
viewsA: Save data from an array to a database
You have some options, use Entityframework, Dapper, ADO Net or any other. I will put here two examples of Insert using your object. Now just adapt to your columns and table template and realize the…
-
0
votes1
answer13
viewsA: error loading Progressring (Mahapps)
You’re in trouble because you’re running this in another thread. o . NET has a class called Backgroundworker, which provides methods to report thread progress in an event. The event is automatically…