0

I am working on converting some code and I am no longer using Recordsets and I am using datasets with SqlClient namespace. The code below is what I am trying to convert (ADODB to SqlClient). The datatype in SQL is datetime. Could I use a data table in place of a recordset? What is the best way to approach this? I did find a similar post Here but its doesnt fully answer my question.

else if (DateTime.Now - rs.Fields["time_of_lock"].Value < TimeSpan.FromMinutes(15))
Rich412
  • 11
  • 1
    .NET never had recordsets. It was DataTables or data readers from the start. – Panagiotis Kanavos Dec 04 '19 at 14:56
  • @PanagiotisKanavos Check [Here](https://www.c-sharpcorner.com/UploadFile/9a81a4/adodb-connection-in-net-application-using-C-Sharp/) – Rich412 Dec 04 '19 at 16:10
  • The solution to your problem is to delete any code using ADODB and use ADO.NET. Hackers read SO too and use such vulnerabilities to find targets. If you think that's an exaggeration, check [Preventing the Top Security Weaknesses Found in Stack Overflow Code Snippets](https://stackoverflow.blog/2019/12/02/preventing-the-top-security-weaknesses-found-in-stack-overflow-code-snippets/) from SO's own blog. Whoever uses that article's code doesn't just have a very slow application. They put on a t-shirt saying "Hack Me" – Panagiotis Kanavos Dec 04 '19 at 16:28
  • @PanagiotisKanavos Which is exactly what I am trying to do. SqlClient is under the ADO.net umbrella. So why did I get a down vote when I clearly stated in my question I am converting old code this is currently ADODB to SqlClient ? – Rich412 Dec 04 '19 at 17:27
  • Is there a chunk of new code that you've tried that is not working? – Learning2Code Dec 04 '19 at 17:45
  • @Learning2Code The issue i am running into is subtracting `datetime` from the value in `SQL`. Im not sure how to go about it using `SqlClient` – Rich412 Dec 04 '19 at 19:28
  • I think https://www.mssqltips.com/sqlservertip/5771/querying-sql-server-tables-from-net/ is a good place for you to start. – howcheng Dec 04 '19 at 22:11
  • If you are more concerned with handling things on the C# side, try https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/dataadapters-and-datareaders and/or https://stackoverflow.com/questions/5619216/reading-a-date-using-datareader – Learning2Code Dec 05 '19 at 00:07
  • @Rich412 if you use ADO.NET and a call to [DbCommand.ExecuteReader()](https://learn.microsoft.com/en-us/dotnet/api/system.data.common.dbcommand.executereader?view=netframework-4.8) you can get a reader and read dates directly with [DbDataReader.GetDateTime](https://learn.microsoft.com/en-us/dotnet/api/system.data.common.dbdatareader.getdatetime?view=netframework-4.8). That's how people have been working for 19 years, and what all .NET tutorials show since 2002. – Panagiotis Kanavos Dec 05 '19 at 08:41

0 Answers0