Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7491019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:48:50+00:00 2026-05-29T15:48:50+00:00

when I input data are not yet available. button does not work but when

  • 0

when I input data are not yet available. button does not work
but when I enter existing data in the database, the button work for find existing records in the database and msgbox.appear
this my coding. (i am using Microsoft Visual Basic 2008 express edition database mysql)

Imports MySql.Data.MySqlClient
Public Class Form2
    Public conn As MySqlConnection
    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Application.DoEvents()
        Button1.Focus()

        conn = New MySqlConnection
        'conn.ConnectionString = "server=localhost;database=ilmu;userid=root;password= ''"
        Try
            conn.Open()
        Catch ex As Exception
            MessageBox.Show("Error1: " & ex.Message)
        End Try
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        conn = New MySqlConnection("server=localhost;database=ilmu;userid=root;password= ''")
        Try
            conn.Open()
            Dim sqlquery As String = "SELECT * FROM visitor WHERE nama = '" & TextBox1.Text & "';"
            Dim data As MySqlDataReader
            Dim adapter As New MySqlDataAdapter
            Dim command As New MySqlCommand
            command.CommandText = sqlquery
            command.Connection = conn
            adapter.SelectCommand = command
            data = command.ExecuteReader
            While data.Read()
                If data.HasRows() = True Then
                    If data(2).ToString = TextBox2.Text Then
                        command = New MySqlCommand
                        command.Connection = conn
                        tkhupd = Now.ToString("yyyy-MM-dd HH:mm:tt")
                        command.CommandText = "INSERT INTO visitor(noK,khupd)VALUES ('" & TextBox1.Text & "','" & tkhupd & "')"
                        command.ExecuteNonQuery()
                        MessageBox.Show(" Berjaya, Sila Masuk. ", "Tahniah", MessageBoxButtons.OK, MessageBoxIcon.Information)

                    Else
                        MsgBox("exist")

                    End If
                Else
                    MsgBox("Failed Login.")
                End If
            End While

        Catch ex As Exception

        End Try
    End Sub
End Class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T15:48:53+00:00Added an answer on May 29, 2026 at 3:48 pm

    I am not sure what you are trying to do when there is not matching record in the database, but you don’t have any code that would be hit in the case of no matching entries.

    If there are no matching records, your while condition isn’t met and nothing in the loop happens.

    Fixing it likely involves rearranging the order of your loop and your if condition.

    Check to see if data.hasRows first.

    Example:

    If data.HasRows() = True Then
       While Data.Read
           //code here for found rows
       End While
     Else
        //code for no matching entries
     End If
    

    And as has been mentioned in Joel’s comment, you really should look at using parameterized queries.

    example of your insert command altered:

     command.CommandText = "INSERT INTO visitor(noK,khupd)VALUES (?noK,?khupd)"
     command.Parameters.AddWithValue("?noK",TextBox1.Text)
     command.Parameters.AddWithValue("?khupd", tkhupd)
     command.ExecuteNonQuery()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried using PARSE on a PORT! and it does not work: >> parse
We have some input data that sometimes appears with &nbsp characters on the end.
Is it enough to avoid javascript injection validating input data in such way: xssValidate
I need to build an application that accepts user input data (such as name,
I'm currently working on a reasonably complicated data input form, based around ASP.NET Web
I am writting an application that autogenerated the data input UI from a java
I know it's possible to use validators to check data input in the presentation
I've learned how to store a single input of data and return a value
In my scenario, I have a program that analyzes data input files and produces
See updated input and output data at Edit-1. What I am trying to accomplish

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.