C
C#2y ago
NDOT

❔ How read data returned from a query?

See dotnetbot
14 Replies
Angius
Angius2y ago
You can type in your question whole when creating the topic, no need to leave it for a separate comment Just so you know
NDOT
NDOT2y ago
ok my bad next time i'll write it before but, i just wanna know how can i read the answer of a query i'm used with the Angular server, that usually takes some hours/days to people help you 1- i made a query that gets me a value 2- i wanna take this value and compare with another variable
Angius
Angius2y ago
Show some $code
MODiX
MODiX2y ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat If your code is too long, post it to: https://paste.mod.gg/
NDOT
NDOT2y ago
string query = @"SELECT yesOrNo AS 'CHECK',semiID,Nome,Sobrenome, dataApontamento, motivo
FROM Qualidade_Apontamento_Seguro
AS A LEFT JOIN AspNetUsers as B ON A.userApontamento = B.Id
where yesOrNo = 0 AND dataApontamento = @data AND semiID = @id;";

SqlCommand cmd = new SqlCommand(query, sqlconn, tran);

cmd.Parameters.Add("@id", SqlDbType.VarChar).Value = idUsuario;
cmd.Parameters.Add("@data",SqlDbType.VarChar).Value = Date;
// if(string Date = DateSql){things happen} (imagine that i compare the values there)
string query = @"SELECT yesOrNo AS 'CHECK',semiID,Nome,Sobrenome, dataApontamento, motivo
FROM Qualidade_Apontamento_Seguro
AS A LEFT JOIN AspNetUsers as B ON A.userApontamento = B.Id
where yesOrNo = 0 AND dataApontamento = @data AND semiID = @id;";

SqlCommand cmd = new SqlCommand(query, sqlconn, tran);

cmd.Parameters.Add("@id", SqlDbType.VarChar).Value = idUsuario;
cmd.Parameters.Add("@data",SqlDbType.VarChar).Value = Date;
// if(string Date = DateSql){things happen} (imagine that i compare the values there)
i send a parameter (actual date) and want to find if there's rows in the same date with an specific ID
Angius
Angius2y ago
Ah, using regular ol' ADO.NET
Angius
Angius2y ago
SqlCommand Class (System.Data.SqlClient)
Represents a Transact-SQL statement or stored procedure to execute against a SQL Server database. This class cannot be inherited.
Angius
Angius2y ago
Here's an example of retrieving the data Long and painful, but that's ADO for you
NDOT
NDOT2y ago
HM, i'll take a read btw the another question that i did about getting actual date without time worked perfectly, thanks
Angius
Angius2y ago
nice
NDOT
NDOT2y ago
thanks, next time i'll elaborate the question first
Angius
Angius2y ago
A protip for the database, too: if you don't have any restrictions as to what libraries and stuff you can use, consider using Dapper instead of ADO Makes code much more sane Lets you map SQL query results directly to C# objects
NDOT
NDOT2y ago
hmm that's awesome i'll search about it thanks we actually just use pure Winforms + SQLServer using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.