Search DB

Was wondering if someone can help me with the following question? I want to search a DB and find the highest value in the DB in a particular column (the column is simply called High) for the last 14 days (DB gets automatically updated with new data every day, except weekends) and then want that value displayed in a messagebox
citadellondonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

citadellondonAuthor Commented:
Any assitance is greatly appreciated
citadellondonAuthor Commented:
Oh need to search from within a VB .NET application
TDSnetCommented:
What DBMS are you using..?  Here's the MS SQL Server (TransactSQL) answer...You should be able to adapt to whatever standard you are using:

Select Max(High)
  From MyTable
 Where DateField >= DateAdd(Day, -14, GetDate())

Replace "MyTable" with your table name and replace "DateField" with the name of your field containing the date.

Jack
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

TDSnetCommented:
Sorry just realised...Do you need all the ADO code as well so you can execute that SQL statement from your code or do you know how to do that..?
citadellondonAuthor Commented:
if you could kindly provide the ado code that would be great

P.s I am using an Access DB
TDSnetCommented:
Okay...You would need something similar to the following:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  Dim cnn As New OleDbConnection
  Dim cmd As New OleDbCommand
  Dim val As Int32

  cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Temp\Db1.mdb"
  cnn.Open()

  cmd.Connection = cnn
  cmd.CommandText = "Select Max(High) From TableName Where DateField >= DateAdd('d', -14, Now())"

  val = cmd.ExecuteScalar
  MessageBox.Show(val)

  cnn.Close()
  cnn.Dispose()
  cmd.Dispose()
End Sub

You will have to change the ConnectionString to contain the path to your (.mdb) file.

Jack

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.