Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. SQL Check if a record exists

SQL Check if a record exists

Scheduled Pinned Locked Moved Visual Basic
questiondatabasecomtools
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    The ANZAC
    wrote on last edited by
    #1

    Look...i'm really not good with sql since i don't do it that often...can someone please give me a really dumbed down answer so i understand. I am sorta just getting into using sql. How do i check if a record exists, i need to know everything, i have a table called users. When a user puts a username in a textbox, how do i check if a record exists with there user name.

    Please check out my articles: The ANZAC's articles

    T V 2 Replies Last reply
    0
    • T The ANZAC

      Look...i'm really not good with sql since i don't do it that often...can someone please give me a really dumbed down answer so i understand. I am sorta just getting into using sql. How do i check if a record exists, i need to know everything, i have a table called users. When a user puts a username in a textbox, how do i check if a record exists with there user name.

      Please check out my articles: The ANZAC's articles

      T Offline
      T Offline
      Tom Deketelaere
      wrote on last edited by
      #2

      just put it in the where clause and check if you get a record back: sql: select username from users where username='me' then you just check you'r datareader/adapter if there is a record in it if so the user exist of not the user doesn't exist hope this helps

      If my help was helpfull let me know, if not let me know why. The only way we learn is by making mistaks.

      T 1 Reply Last reply
      0
      • T The ANZAC

        Look...i'm really not good with sql since i don't do it that often...can someone please give me a really dumbed down answer so i understand. I am sorta just getting into using sql. How do i check if a record exists, i need to know everything, i have a table called users. When a user puts a username in a textbox, how do i check if a record exists with there user name.

        Please check out my articles: The ANZAC's articles

        V Offline
        V Offline
        Vimalsoft Pty Ltd
        wrote on last edited by
        #3

        HI The ANZAC Follow me. Lets say i have a textbox in my form and i want to see if there is a user name that Exist in my table "Users", and am using VB.NET. the First thing is to set up the adapter. you must tell the adapter that you going to Accept inputs from users. e.g

        SELECT USERS FROM MYTABLE WHERE (USERNAME = @USERNAME)

        When you are done with that create a dataset and Fill your dataset with Data like this.

        myadapter.Fill(mydataset)

        After that , you need to call this from your form. in your form put in a Button , call it "btnSearch", and in the button click event write the Following code.

        try

        myadapter.SelectCommand.Parameters("@Username").Value = txtUsername.Text
        mydataset.Clear()
        myadapter.Fill( mydataset, "MYTable")
        If mydataset.Tables("MYTable").Rows.Count = 0 Then
        MessageBox.Show("The USERNAME does not Exist in the Database you can Continue Add it", "Info", MessageBoxButtons.OK)
        Else
        MessageBox.Show("The Property Exist in the Database, you cannot Add this liskey", "Error", MessageBoxButtons.OK)
        End If
        Catch ex As SqlClient.SqlException
        MessageBox.Show(ex.Message)
        End Try

        Hope this Helps, if doesnt TEll me

        Vuyiswa Maseko, Sorrow is Better than Laughter, it may Sudden your Face, but It sharpens your Understanding VB.NET/SQL7/2000/2005 http://vuyiswamb.007ihost.com http://Ecadre.007ihost.com vuyiswam@tshwane.gov.za

        T 1 Reply Last reply
        0
        • V Vimalsoft Pty Ltd

          HI The ANZAC Follow me. Lets say i have a textbox in my form and i want to see if there is a user name that Exist in my table "Users", and am using VB.NET. the First thing is to set up the adapter. you must tell the adapter that you going to Accept inputs from users. e.g

          SELECT USERS FROM MYTABLE WHERE (USERNAME = @USERNAME)

          When you are done with that create a dataset and Fill your dataset with Data like this.

          myadapter.Fill(mydataset)

          After that , you need to call this from your form. in your form put in a Button , call it "btnSearch", and in the button click event write the Following code.

          try

          myadapter.SelectCommand.Parameters("@Username").Value = txtUsername.Text
          mydataset.Clear()
          myadapter.Fill( mydataset, "MYTable")
          If mydataset.Tables("MYTable").Rows.Count = 0 Then
          MessageBox.Show("The USERNAME does not Exist in the Database you can Continue Add it", "Info", MessageBoxButtons.OK)
          Else
          MessageBox.Show("The Property Exist in the Database, you cannot Add this liskey", "Error", MessageBoxButtons.OK)
          End If
          Catch ex As SqlClient.SqlException
          MessageBox.Show(ex.Message)
          End Try

          Hope this Helps, if doesnt TEll me

          Vuyiswa Maseko, Sorrow is Better than Laughter, it may Sudden your Face, but It sharpens your Understanding VB.NET/SQL7/2000/2005 http://vuyiswamb.007ihost.com http://Ecadre.007ihost.com vuyiswam@tshwane.gov.za

          T Offline
          T Offline
          The ANZAC
          wrote on last edited by
          #4

          This is helping, but where do i put that select statement, i am really new to this.

          Please check out my articles: The ANZAC's articles

          V 1 Reply Last reply
          0
          • T Tom Deketelaere

            just put it in the where clause and check if you get a record back: sql: select username from users where username='me' then you just check you'r datareader/adapter if there is a record in it if so the user exist of not the user doesn't exist hope this helps

            If my help was helpfull let me know, if not let me know why. The only way we learn is by making mistaks.

            T Offline
            T Offline
            The ANZAC
            wrote on last edited by
            #5

            i appreciate the help, but i am not at all database experienced and to me this is extremely vague, i'm seriously like a lost sheep when it comes to this, you need to be really detailed for me. thanks though.

            Please check out my articles: The ANZAC's articles

            1 Reply Last reply
            0
            • T The ANZAC

              This is helping, but where do i put that select statement, i am really new to this.

              Please check out my articles: The ANZAC's articles

              V Offline
              V Offline
              Vimalsoft Pty Ltd
              wrote on last edited by
              #6

              i suggest you use the Wizard for now, as you are new. drag an Adapter from your ToolBox, The wizard will popin and Click next, if you have no Connection create a new one, if you are using Access as a Backend choose JET4 provider and select where the database is and test the connection. after that right click on the adapter and choose Configure the adapter --> and you will see that database had been selected and click next-->:Choose the First Opttion "Use SQl statement", ---> Next this Part its where you put your SQL statement, after that you will click next, all neccessary command statement will be generated for Update, select and Delete and Click Finish hope it Helps

              Vuyiswa Maseko, Sorrow is Better than Laughter, it may Sudden your Face, but It sharpens your Understanding VB.NET/SQL7/2000/2005 http://vuyiswamb.007ihost.com http://Ecadre.007ihost.com vuyiswam@tshwane.gov.za

              T 1 Reply Last reply
              0
              • V Vimalsoft Pty Ltd

                i suggest you use the Wizard for now, as you are new. drag an Adapter from your ToolBox, The wizard will popin and Click next, if you have no Connection create a new one, if you are using Access as a Backend choose JET4 provider and select where the database is and test the connection. after that right click on the adapter and choose Configure the adapter --> and you will see that database had been selected and click next-->:Choose the First Opttion "Use SQl statement", ---> Next this Part its where you put your SQL statement, after that you will click next, all neccessary command statement will be generated for Update, select and Delete and Click Finish hope it Helps

                Vuyiswa Maseko, Sorrow is Better than Laughter, it may Sudden your Face, but It sharpens your Understanding VB.NET/SQL7/2000/2005 http://vuyiswamb.007ihost.com http://Ecadre.007ihost.com vuyiswam@tshwane.gov.za

                T Offline
                T Offline
                The ANZAC
                wrote on last edited by
                #7

                This has helped. I managed to do it slightly different..in that it counts the amount of users which have the same name as the above. select count(*)

                Please check out my articles: The ANZAC's articles

                V 1 Reply Last reply
                0
                • T The ANZAC

                  This has helped. I managed to do it slightly different..in that it counts the amount of users which have the same name as the above. select count(*)

                  Please check out my articles: The ANZAC's articles

                  V Offline
                  V Offline
                  Vimalsoft Pty Ltd
                  wrote on last edited by
                  #8

                  AM Glad i helped you

                  Vuyiswa Maseko, Sorrow is Better than Laughter, it may Sudden your Face, but It sharpens your Understanding VB.NET/SQL7/2000/2005 http://vuyiswamb.007ihost.com http://Ecadre.007ihost.com vuyiswam@tshwane.gov.za

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups