Click here to Skip to main content
15,920,836 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Is VB.Net under-rated? Pin
markrlondon13-Apr-20 11:27
markrlondon13-Apr-20 11:27 
AnswerRe: Is VB.Net under-rated? Pin
Mycroft Holmes28-Feb-20 11:22
professionalMycroft Holmes28-Feb-20 11:22 
GeneralRe: Is VB.Net under-rated? Pin
markrlondon13-Apr-20 11:28
markrlondon13-Apr-20 11:28 
QuestionVB.NET/MS ACCESS Saving today's date produces 2020-02-25 08:28:00.946341400 Pin
Member 1186689325-Feb-20 2:39
Member 1186689325-Feb-20 2:39 
AnswerRe: VB.NET/MS ACCESS Saving today's date produces 2020-02-25 08:28:00.946341400 Pin
Richard MacCutchan25-Feb-20 3:07
mveRichard MacCutchan25-Feb-20 3:07 
GeneralRe: VB.NET/MS ACCESS Saving today's date produces 2020-02-25 08:28:00.946341400 Pin
Member 1186689325-Feb-20 3:18
Member 1186689325-Feb-20 3:18 
GeneralRe: VB.NET/MS ACCESS Saving today's date produces 2020-02-25 08:28:00.946341400 Pin
Richard MacCutchan25-Feb-20 3:33
mveRichard MacCutchan25-Feb-20 3:33 
GeneralRe: VB.NET/MS ACCESS Saving today's date produces 2020-02-25 08:28:00.946341400 Pin
Member 1186689325-Feb-20 3:32
Member 1186689325-Feb-20 3:32 
GeneralRe: VB.NET/MS ACCESS Saving today's date produces 2020-02-25 08:28:00.946341400 Pin
Richard MacCutchan25-Feb-20 3:37
mveRichard MacCutchan25-Feb-20 3:37 
GeneralRe: VB.NET/MS ACCESS Saving today's date produces 2020-02-25 08:28:00.946341400 Pin
Member 1186689325-Feb-20 6:37
Member 1186689325-Feb-20 6:37 
GeneralRe: VB.NET/MS ACCESS Saving today's date produces 2020-02-25 08:28:00.946341400 Pin
Richard MacCutchan25-Feb-20 6:43
mveRichard MacCutchan25-Feb-20 6:43 
GeneralMessage Closed Pin
25-Feb-20 6:55
Member 1186689325-Feb-20 6:55 
GeneralRe: VB.NET/MS ACCESS Saving today's date produces 2020-02-25 08:28:00.946341400 Pin
Eddy Vluggen25-Feb-20 8:02
professionalEddy Vluggen25-Feb-20 8:02 
GeneralRe: VB.NET/MS ACCESS Saving today's date produces 2020-02-25 08:28:00.946341400 Pin
phil.o25-Feb-20 8:18
professionalphil.o25-Feb-20 8:18 
GeneralRe: VB.NET/MS ACCESS Saving today's date produces 2020-02-25 08:28:00.946341400 Pin
Richard MacCutchan25-Feb-20 8:18
mveRichard MacCutchan25-Feb-20 8:18 
GeneralRe: VB.NET/MS ACCESS Saving today's date produces 2020-02-25 08:28:00.946341400 Pin
Eddy Vluggen25-Feb-20 8:44
professionalEddy Vluggen25-Feb-20 8:44 
GeneralRe: VB.NET/MS ACCESS Saving today's date produces 2020-02-25 08:28:00.946341400 Pin
Richard MacCutchan25-Feb-20 8:49
mveRichard MacCutchan25-Feb-20 8:49 
GeneralRe: VB.NET/MS ACCESS Saving today's date produces 2020-02-25 08:28:00.946341400 Pin
Eddy Vluggen25-Feb-20 12:19
professionalEddy Vluggen25-Feb-20 12:19 
GeneralRe: VB.NET/MS ACCESS Saving today's date produces 2020-02-25 08:28:00.946341400 Pin
Richard MacCutchan25-Feb-20 21:09
mveRichard MacCutchan25-Feb-20 21:09 
QuestionRe: VB.NET/MS ACCESS Saving today's date produces 2020-02-25 08:28:00.946341400 Pin
ZurdoDev28-Feb-20 6:55
professionalZurdoDev28-Feb-20 6:55 
AnswerRe: VB.NET/MS ACCESS Saving today's date produces 2020-02-25 08:28:00.946341400 Pin
phil.o25-Feb-20 8:24
professionalphil.o25-Feb-20 8:24 
AnswerRe: VB.NET/MS ACCESS Saving today's date produces 2020-02-25 08:28:00.946341400 Pin
Mycroft Holmes25-Feb-20 11:44
professionalMycroft Holmes25-Feb-20 11:44 
QuestionVB.NET/MS ACCESS Display data from query Pin
Member 1186689321-Feb-20 3:05
Member 1186689321-Feb-20 3:05 
AnswerRe: VB.NET/MS ACCESS Display data from query Pin
Richard Deeming21-Feb-20 3:40
mveRichard Deeming21-Feb-20 3:40 
It's selecting all records from the table. You then iterate through the results, overwriting the textbox with the next value, until you get to the last record in the table.

You need a WHERE clause to select just the record you're interested in. And you need to make sure you use parameters to avoid a SQL Injection[^] vulnerability.

There's also no need to use ExecuteReader to read a single value from a single row; use ExecuteScalar instead.

Try something like this:
VB.NET
Private Sub tbStudentID2_TextChanged(sender As Object, e As EventArgs) Handles tbStudentID2.TextChanged
    Dim studentID As Integer
    If Not Integer.TryParse(tbStudentID2.Text, studentID) Then
        ' Not a valid ID
        txtDays.Text = String.Empty
    Else
        Using command As New OleDbCommand("SELECT DateDiff('d', [DateofRank], [currentDate]) FROM StudentData WHERE StudentID = @StudentID", myConnection)
            command.Parameters.AddWithValue("@StudentID", studentID)
            
            ConnDB()
            
            Dim days As Object = command.ExecuteScalar()
            txtDays.Text = If(Convert.IsDBNull(days), String.Empty, Convert.ToString(days))
        End Using
    End If
End Sub
Int32.TryParse Method (System) | Microsoft Docs[^]
OleDbCommand.ExecuteScalar Method (System.Data.OleDb) | Microsoft Docs[^]



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: VB.NET/MS ACCESS Display data from query Pin
Member 1186689321-Feb-20 4:10
Member 1186689321-Feb-20 4:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.