Click here to Skip to main content
15,883,940 members
Home / Discussions / Visual Basic
   

Visual Basic

 
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 
AnswerRe: VB.NET/MS ACCESS Display data from query Pin
Member 1186689321-Feb-20 4:39
Member 1186689321-Feb-20 4:39 
QuestionVB.NET/MS ACCESS Fill column and all entries in the that column with the current date Pin
Member 1186689320-Feb-20 4:14
Member 1186689320-Feb-20 4:14 
AnswerRe: VB.NET/MS ACCESS Fill column and all entries in the that column with the current date Pin
ZurdoDev20-Feb-20 4:23
professionalZurdoDev20-Feb-20 4:23 
GeneralRe: VB.NET/MS ACCESS Fill column and all entries in the that column with the current date Pin
Member 1186689320-Feb-20 4:44
Member 1186689320-Feb-20 4:44 
AnswerRe: VB.NET/MS ACCESS Fill column and all entries in the that column with the current date Pin
ZurdoDev20-Feb-20 5:28
professionalZurdoDev20-Feb-20 5:28 
AnswerRe: VB.NET/MS ACCESS Fill column and all entries in the that column with the current date Pin
Richard MacCutchan20-Feb-20 4:58
mveRichard MacCutchan20-Feb-20 4:58 
GeneralRe: VB.NET/MS ACCESS Fill column and all entries in the that column with the current date Pin
Member 1186689320-Feb-20 5:39
Member 1186689320-Feb-20 5:39 
GeneralRe: VB.NET/MS ACCESS Fill column and all entries in the that column with the current date Pin
Dave Kreskowiak20-Feb-20 7:13
mveDave Kreskowiak20-Feb-20 7:13 
GeneralRe: VB.NET/MS ACCESS Fill column and all entries in the that column with the current date Pin
Member 1186689320-Feb-20 5:42
Member 1186689320-Feb-20 5:42 
QuestionHow to create new DateTime of months, going back 12 months Pin
jkirkerx17-Feb-20 8:32
professionaljkirkerx17-Feb-20 8:32 
AnswerRe: How to create new DateTime of months, going back 12 months [it works] Pin
jkirkerx17-Feb-20 8:52
professionaljkirkerx17-Feb-20 8:52 
AnswerRe: How to create new DateTime of months, going back 12 months Pin
Richard Deeming18-Feb-20 2:20
mveRichard Deeming18-Feb-20 2:20 
GeneralRe: How to create new DateTime of months, going back 12 months Pin
jkirkerx18-Feb-20 7:18
professionaljkirkerx18-Feb-20 7:18 
GeneralRe: How to create new DateTime of months, going back 12 months Pin
Richard Deeming18-Feb-20 7:42
mveRichard Deeming18-Feb-20 7:42 
QuestionHOW TO CREATE RDLC REPORT AND CALL IN VS 2013 Pin
Member 146289475-Feb-20 0:39
Member 146289475-Feb-20 0:39 
AnswerRe: HOW TO CREATE RDLC REPORT AND CALL IN VS 2013 Pin
Richard MacCutchan5-Feb-20 2:11
mveRichard MacCutchan5-Feb-20 2:11 

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.