Posts by João Martins • 5,597 points
279 posts
-
1
votes1
answer44
viewsA: Refactor code using LINQ in C#
Eventually there will be another way to do it (which is normal in LINQ), but here goes a solution: public List<Ponto> Filtrar(IQueryable<Ponto> pontosFiltrados, List<Usuario>…
-
0
votes1
answer36
viewsA: How do I make a Total Current?
Create a running total in SQL Server is relatively simple. Not having the whole context, I believe that the query below solves the problem: SELECT ft.nmdoc , ft.fno , ft.fdata , Valor_Doc =…
-
0
votes1
answer59
viewsA: When I run my SQL function it returns NULL, even with data entered in the database
I imagine that the query should only return a result, since all the later logic takes into account variables whose value is obtained from the query itself. The consultation seems to me to have…
-
3
votes2
answers180
viewsA: Receive data in a matrix c#
I believe you’re using Array for some kind of academic work, hence the use of List should be out of the question. Resizing a Array, something that is quite simple and direct using the Array.Resize…
-
0
votes2
answers74
viewsA: Select to Alias
What you want can be solved using dynamic SQL: DECLARE @SQL NVARCHAR(1000) SET @SQL = 'SELECT 1 AS ''' + (SELECT dia_da_semana FROM ano WHERE dia = 1 AND mes = 10) + '''' EXEC(@SQL)…
-
2
votes3
answers454
viewsA: Replace Sql in the middle of the text
The solution should also replace the name of the month with the number so that it is a valid date. Below is one of the possible solutions (created an example table, Datas): ;WITH CTE(NumMes, Mes) AS…
-
2
votes1
answer80
viewsA: Datagridview Dataset Problem [C#]
I think the easiest way, and maybe avoiding the error, will be to change the DataTable associated with DataGridView and then do the assignment again: DataTable dt =…
-
3
votes1
answer96
viewsA: Question with SELECT instruction from a self-relative table
If you read the article Visual Representation of SQL Joins in the Codeproject will be able to quickly understand why the behavior. In your case it would be as follows: Basically, a LEFT JOIN allows…
-
0
votes2
answers33
viewsA: Hiddenfield value always zero
To get the value of HiddenField need to go through the property Value: if (_index == row.RowIndex) { _id = ((HiddenField)row.Cells[0].FindControl("hiddenid")).Value; }…
-
2
votes1
answer285
viewsA: Opacity of images C#
Example found in Change Opacity of Image in C#: /// <summary> /// method for changing the opacity of an image /// </summary> /// <param name="image">image to set opacity…
-
0
votes2
answers593
viewsA: C# - High memory consumption
The GC (Garbage Colector) only liberates memory of Managed code and/or Managed Resources, where in cases that are not included in this scenario it is necessary to implement routines to free…
-
0
votes2
answers49
viewsA: Optimization/correction in "Dbcontext.Savechanges()"
I managed to solve the problem with a more "raw" solution, where I basically do the INSERT directly in the database without going through EPH: using (TransactionScope scope = new TransactionScope())…
-
2
votes1
answer650
viewsA: C# - Windows Form how to search in a Datagridview
The simplest way to filter a DataGridView is using a DataTable, which allows root filtering, sorting columns, etc. How, apparently, you’re using a List, then it is necessary to implement a…
-
1
votes2
answers49
viewsQ: Optimization/correction in "Dbcontext.Savechanges()"
having regard to the following scenario:: using (TransactionScope scope = new TransactionScope()) { var allObjects = new List<MyObject>(); var objects = myStaticClass.GetAllObjects(); foreach…
-
0
votes1
answer147
viewsA: Print in landscape format in Crystal report
Maybe so? rptTemp.PrintOptions.PaperOrientation = PaperOrientation.Landscape Being the object rptTemp the report Viewer.
-
2
votes1
answer43
viewsA: c# visual studio!! how do I get my form to occupy the entire screen? it’s only half the screen!
If it is WPF, in XAML just use the following: HorizontalAlignment="Stretch" VerticalAlignment="Stretch" If it is Winforms, just change the option Dock for Fill: tabControl1.Dock = DockStyle.Fill; Or…
c#answered João Martins 5,597 -
0
votes2
answers39
viewsA: Complete number of query records
The solution is to consult a set of pre-defined records with the months, then join the table of rents: SELECT M.Nome , SUM(IFNULL(Renda, 0)) AS Renda FROM ( SELECT "Mes 01" AS Nome, 1 AS Mes UNION…
-
3
votes3
answers1436
viewsA: SQL - Two different WHERE conditions for the same SELECT
You will have to evaluate the variable @show within itself WHERE: SELECT * FROM xxx d INNER JOIN yyy ds ON ds.id_xxx = d.id WHERE d.statusId = (CASE WHEN @show = 1 THEN ds.id END) OR d.statusId…
-
0
votes1
answer59
viewsA: Add data from two tables with same parameters
Taking into account only existing boards in both tables, titulospagar and titulosavulsos: SELECT A.placa , A.valorTitulosPagar , B.valorTitulosAvulsos FROM ( SELECT placa , SUM(valor) AS…
-
1
votes1
answer254
viewsA: Simple Quotes in Access
To solve this case you need to duplicate the quotes so that the text is accepted by SQL. Create this function: Private Function TrataAspasSimples(ByVal strTexto As String) If InStr(strTexto, "'")…
-
5
votes2
answers334
viewsA: Perform a DELETE with Where being the result of a SELECT (MYSQL)
The result of function recall mysqli_query is not a scalar value, but an object of the type mysqli_result (PHP: mysqli::query - Manual). What you need to do is get the date value and then use DELETE…
-
0
votes1
answer54
viewsA: SQL grouping product balance by company
Try it this way: SET @sql = NULL; SELECT GROUP_CONCAT(DISTINCT CONCAT('SUM(CASE WHEN SE.empresa_id = ', id, ' THEN SE.saldo ELSE 0 END) AS ''', nome, '''')) INTO @sql FROM empresa; SET @sql =…
-
0
votes1
answer32
viewsA: Mysql to SQL Sever
In SQL Server it would be something like this: EXEC sp_columns [TABLE 2] ALTER TABLE [TABLE 2] ADD [COLL 44] VARCHAR(20) NULL ALTER TABLE [TABLE 2] ADD [COLL 45] VARCHAR(20) NULL ALTER TABLE [TABLE…
-
0
votes1
answer18
viewsA: Unknow table in field list when performing select + sum
To be able to sum up you need to identify the source tables of each field you are using. In this case it would be something like this (without knowing the structure of the two tables but assuming…
-
0
votes1
answer43
viewsA: Compare tables and add result to row
I think the query below returns what you want: SELECT DISTINCT T2.* , T1.N3_CUSTBEM , T1.N3_VORIG1 , T1.N3_TXDEPR1 , T1.N3_VRDACM1 FROM T2 INNER JOIN T1 ON T1.N3_FILIAL = T2.N4_FILIAL AND…
-
0
votes3
answers202
viewsA: Sql query bring repeated result
If you wish to obtain only those records, with sum of quantity, whose key setor + usuario has duplicates, can use the following solution: SELECT setor , SUM(quantidade) AS quantidade FROM…
-
0
votes1
answer26
viewsA: Fetch field name and Insert into
To get the columns of a given table in Mysql just do the following: SHOW COLUMNS FROM tabela; The properties that may interest you will be: Field (column name) Type (type of data in the column) Then…
-
0
votes2
answers213
viewsA: Modify attributes of a label with a dynamic name
After creating your controls: // Exemplo de criação de 3 labels for (int i = 1; i <= 3; i++) { Label label = new Label() { Name = "Lbl" + i.ToString(), Text = $"Label " + i.ToString() };…
-
1
votes1
answer828
viewsA: Read tag fields in XML VB.Net
Here is an example that can help you in the solution: Dim strXml As String = "<xml> <det nItem=""1""> <prod> <cProd>7898577370182</cProd> <xProd>J.WATANABE/COUVE…
-
0
votes1
answer36
viewsA: Table with default value not loaded
If it is possible to remove the column and recreate, you can always do the following: ALTER TABLE Revenda DROP COLUMN GrupoDescontoId ALTER TABLE Revenda ADD GrupoDescontoId INT CONSTRAINT…
-
0
votes2
answers95
viewsA: Query including multiple tables
Using two LEFT JOIN can perfectly relate the 3 tables: SELECT bpm.nomepessoa as pessoa , ISNULL(mae.nomepessoa, '') AS mae , ISNULL(pai.nomepessoa, '') AS pai FROM bpm_pessoa bpm LEFT JOIN ( SELECT…
-
2
votes1
answer77
viewsA: How to upload multiple images to Cloudinary?
On the estate PublicId, you need to put a different file name. Example: "my_folder/images/image1" "my_folder/images/image2" "my_folder/images/image3" Follows code: string[] files =…
c#answered João Martins 5,597 -
3
votes1
answer137
viewsA: Entity Framework returns any type of data with Sqlquery
Why not use a generic list (untested code)? public static List<T> GetQuery<T>(string NomeCampo, string Tabela, int id) where T : class { comandoSql = $" SELECT {NomeCampo} FROM {Tabela}…
-
0
votes2
answers120
viewsA: Oracle SQL - Return of the first record between two dates
Try it this way: SELECT T.* FROM tabela T LEFT JOIN ( SELECT codigo , dataproducao , ROW_NUMBER() OVER (PARTITION BY codigo ORDER BY dataproducao) AS rn FROM tabela ) T2 ON T2.codigo = T.codigo AND…
-
1
votes3
answers839
viewsA: how to select zero Count
Try this way (in SQL Server): SELECT M.nome AS municipio , ISNULL(C.clientes, 0) AS clientes FROM Municipio M LEFT JOIN ( SELECT cidade , COUNT(1) AS clientes FROM Cliente GROUP BY cidade ) C ON…
-
1
votes2
answers54
viewsA: Event call at another event
Personally I think the most correct/"beautiful" way is to create a method that should be evoked in both events: private void dgvCellValueChanged(objectivo Sender, DatagridViewCellEventArgs e) {…
-
2
votes2
answers254
viewsA: Problem calling Virtual Keyboard - Winforms
Try it this way: ProcessStartInfo processStartInfo = new ProcessStartInfo() { UseShellExecute = true, FileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "osk.exe"),…
-
3
votes1
answer105
viewsA: List local windows groups with Forms c#
For local groups maybe this is enough: using System.DirectoryServices; DirectoryEntry machine = new DirectoryEntry("WinNT://" + Environment.MachineName + ",Computer"); if (machine.Children != null)…
-
2
votes2
answers96
viewsA: Readalltext returns Chinese characters
If you already know the encoding used in the file, why not use it to read the file? string s_unicode = File.ReadAllText(path, Encoding.GetEncoding("UTF-16BE")); You can also pass the results to a…
c#answered João Martins 5,597 -
0
votes1
answer94
viewsA: Sql - Concatenate values if field is equal
Given the issue and the comments, I think this will solve your problem: SELECT STUFF( ( SELECT ', ' + codigo + ' ' + situacao FROM tb_cad WHERE (fk_aluno = C.fk_aluno) FOR XML PATH(''), TYPE…
-
0
votes3
answers1324
viewsA: Select records from one record to another in sql server
To do this just use the ROW_NUMBER (Transact-SQL): SELECT * FROM ( SELECT ROW_NUMBER() OVER(ORDER BY id) AS Linha , * FROM tabela ) X WHERE X.Linha BETWEEN 10 AND 50 The column id should be the sort…
-
0
votes3
answers93
viewsA: How I take this amount
If you want to change the SQL query it is easy to get the columns you want: SELECT * FROM ( SELECT user_nome , user_user , user_idade , user_img , (6371 * acos(cos(radians($lat)) *…
-
1
votes1
answer56
viewsA: Error generating class c# from XSD
From what you can tell from XSD, there are two files that are included in schema: <!-- Inclusão do arquivo simpleType--> <xsd:include schemaLocation="sibSimpleType.xsd"/> <!-- -->…
-
3
votes2
answers90
viewsA: UPDATE in a query with multiple entries
Taking into account the information on the issue and comments, maybe this way you can solve the problem: string strSql = string.Format(@" UPDATE Pedidos SET taxaImposto = @taxa WHERE idPedido IN…
-
1
votes1
answer60
viewsA: Authenticating user by AD returns server user instead of local user
You’ve tried it this way? User = System.Web.HttpContext.Current.User; We must ensure that your web.config has the following authentication element: <configuration> <system.web>…
-
1
votes2
answers65
viewsA: How to do a parallelism or asynchronous call in a lambda
There is always the possibility to use the Parallel.ForEach (How to: Write a simple Parallel.Foreach loop): using System.Threading.Tasks; // ... Parallel.ForEach(qry, (q) => { var product = new…
-
1
votes1
answer100
viewsA: Select Row in **Datagridview** right click
There is no "beautiful" way to do it, but there is always something to try: dataGridView1.MouseClick += (s, e) => { if (e.Button == MouseButtons.Left) { dataGridView1.ClearSelection();…
c#answered João Martins 5,597 -
1
votes1
answer505
viewsA: Disable selection for Datagridview c# Windows Forms line
If you have a collection of lines that cannot be selected, then you can do it as follows (assuming the lines 1, 3 and 5 cannot be selected): List<int> linhas = new List<int>() { 1, 3, 5…
c#answered João Martins 5,597 -
1
votes1
answer45
viewsA: Help in riding a lambda from a foreach
I think you can do it this way: var qry = from ro in responseObject where ro.FaixasPreco == null || ro.FaixasPreco.Count() == 0 select new ConsultarPrecoFaixaResponse() { PrecoBRL = ro.ValorProduto,…
-
1
votes1
answer75
viewsA: Datagriedview scrollbar track records - C#
Yes, there is. Let’s assume you have a method where you add the lines to DataGridView by name dataGridView1 (example of line addition per code, without DataBind): dataGridView1.Rows.Add(new[] {…