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. Need Help

Need Help

Scheduled Pinned Locked Moved Visual Basic
databasehelptutorialquestion
10 Posts 6 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.
  • B Offline
    B Offline
    BOREC
    wrote on last edited by
    #1

    I am using VB 2005. trying to create wilcard parameter search. I don't know how to connect variamble Name to the one using in SQL statements. SQL lines in Query builder: SELECT ID, Ime, Priimek, [Službeni telefon], [Službeni GSM], [Domaci telefon], [Privatni GSM], [Elektronska pošta], [Domaci naslov] FROM SLUŽBA WHERE (Priimek LIKE '%' & '@NAME' & '%') And in Form2 I have this code inside button1 object: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim NAME As String NAME = TextBox1.Text Try Me.SLUŽBATableAdapter.FillBy2(Me.TelefonskiImenikDataSet.SLUŽBA, NAME) Catch ex As System.Exception System.Windows.Forms.MessageBox.Show(ex.Message) End Try End Sub can anyone tell me what is wrong here and correct the code, please.I've b een researching a lot and don't find a proper solution. Please Help. The builder doesn't report any error but the button doesn't do a query parameter wildcard search. Variable NAME is underlined with green waveline.It says too many arguments to function FillBy2.

    C L B T 4 Replies Last reply
    0
    • B BOREC

      I am using VB 2005. trying to create wilcard parameter search. I don't know how to connect variamble Name to the one using in SQL statements. SQL lines in Query builder: SELECT ID, Ime, Priimek, [Službeni telefon], [Službeni GSM], [Domaci telefon], [Privatni GSM], [Elektronska pošta], [Domaci naslov] FROM SLUŽBA WHERE (Priimek LIKE '%' & '@NAME' & '%') And in Form2 I have this code inside button1 object: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim NAME As String NAME = TextBox1.Text Try Me.SLUŽBATableAdapter.FillBy2(Me.TelefonskiImenikDataSet.SLUŽBA, NAME) Catch ex As System.Exception System.Windows.Forms.MessageBox.Show(ex.Message) End Try End Sub can anyone tell me what is wrong here and correct the code, please.I've b een researching a lot and don't find a proper solution. Please Help. The builder doesn't report any error but the button doesn't do a query parameter wildcard search. Variable NAME is underlined with green waveline.It says too many arguments to function FillBy2.

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      BOREC wrote:

      '@NAME'

      Remove the apostrophes around the parameter. The apostrophes tell SQL Server to expect a string literal value.

      Upcoming FREE developer events: * Developer Day Scotland Recent blog posts: * Follow up on hiring a software developer * Aarrgghh!! Accidentally pressing the Caps Lock key My website | blog

      B 1 Reply Last reply
      0
      • C Colin Angus Mackay

        BOREC wrote:

        '@NAME'

        Remove the apostrophes around the parameter. The apostrophes tell SQL Server to expect a string literal value.

        Upcoming FREE developer events: * Developer Day Scotland Recent blog posts: * Follow up on hiring a software developer * Aarrgghh!! Accidentally pressing the Caps Lock key My website | blog

        B Offline
        B Offline
        BOREC
        wrote on last edited by
        #3

        Could it be that wildcard parameter search doesn't work because I use Express edition version of the program? When I remove the apostrophes the wizard alerts: Erros in WHERE clause near '@'. Unable to parse query text. I tried a lot ways to create a FillBy2 function with apropriate SQL statements and then call the function in Button_click subroutine but it doesn't work. Has anyone done this at home or office? Can someone post the whole code so I can analyze it. Comments very welcome. Bye

        D C 2 Replies Last reply
        0
        • B BOREC

          Could it be that wildcard parameter search doesn't work because I use Express edition version of the program? When I remove the apostrophes the wizard alerts: Erros in WHERE clause near '@'. Unable to parse query text. I tried a lot ways to create a FillBy2 function with apropriate SQL statements and then call the function in Button_click subroutine but it doesn't work. Has anyone done this at home or office? Can someone post the whole code so I can analyze it. Comments very welcome. Bye

          D Offline
          D Offline
          darkelv
          wrote on last edited by
          #4

          You can pad the value entered by user with '%' before sending it as parameter, ie 1. User type in 'abc' 2. In your code, pad the value to '%abc%' 3. Set the padded value to the parameter. So your selection will just be: WHERE (Priimek LIKE @NAME) By the way, your original selection statement always search for '%@NAME%' <-- no longer a parameter.

          B 1 Reply Last reply
          0
          • D darkelv

            You can pad the value entered by user with '%' before sending it as parameter, ie 1. User type in 'abc' 2. In your code, pad the value to '%abc%' 3. Set the padded value to the parameter. So your selection will just be: WHERE (Priimek LIKE @NAME) By the way, your original selection statement always search for '%@NAME%' <-- no longer a parameter.

            B Offline
            B Offline
            BOREC
            wrote on last edited by
            #5

            I understand this. But what puzzles me is that when I create parameter search using this SQL statement SELECT... FROM ... WHERE ( Priimek = ?) the wizard automaticaly creates a function FillBy the wizard automaticaly creates a function FillBy(Priimek) With a variable Priimek which I can use in this statement Me.SLUŽBATableAdapter.FillBy2(Me.TelefonskiImenikDataSet.SLUŽBA, PriimekToolStripTextBox.Text) But when I create a function with SQL statement WHERE (Priimek LIKE @NAME) I get a function with no parameter. The wizard simply puts it out as FillBy2()<-no parameter. I want to create a parametrized wildcard search. When I write "Klaj" out of "Klajnšek" Lastname in TextBox1 I want that the program displays all records with letters "klaj" in LastName like "Klajnšek" or like "Priklajdorin". I hope you understand. Thank you for help

            modified on Thursday, December 27, 2007 7:55:50 AM

            1 Reply Last reply
            0
            • B BOREC

              Could it be that wildcard parameter search doesn't work because I use Express edition version of the program? When I remove the apostrophes the wizard alerts: Erros in WHERE clause near '@'. Unable to parse query text. I tried a lot ways to create a FillBy2 function with apropriate SQL statements and then call the function in Button_click subroutine but it doesn't work. Has anyone done this at home or office? Can someone post the whole code so I can analyze it. Comments very welcome. Bye

              C Offline
              C Offline
              Colin Angus Mackay
              wrote on last edited by
              #6

              BOREC wrote:

              Could it be that wildcard parameter search doesn't work because I use Express edition version of the program?

              No. Parameters are such a basic feature that the Express edition includes it.

              BOREC wrote:

              When I remove the apostrophes the wizard alerts: Erros in WHERE clause near '@'. Unable to parse query text.

              Wizards!?! Why aren't you writing the code yourself. Wizards won't help you, they hinder you because they only allow limited functionality and produce inefficient code (they do produce correct code though which is their primary aim)

              Upcoming FREE developer events: * Developer Day Scotland Recent blog posts: * Follow up on hiring a software developer * Aarrgghh!! Accidentally pressing the Caps Lock key My website | blog

              B 1 Reply Last reply
              0
              • C Colin Angus Mackay

                BOREC wrote:

                Could it be that wildcard parameter search doesn't work because I use Express edition version of the program?

                No. Parameters are such a basic feature that the Express edition includes it.

                BOREC wrote:

                When I remove the apostrophes the wizard alerts: Erros in WHERE clause near '@'. Unable to parse query text.

                Wizards!?! Why aren't you writing the code yourself. Wizards won't help you, they hinder you because they only allow limited functionality and produce inefficient code (they do produce correct code though which is their primary aim)

                Upcoming FREE developer events: * Developer Day Scotland Recent blog posts: * Follow up on hiring a software developer * Aarrgghh!! Accidentally pressing the Caps Lock key My website | blog

                B Offline
                B Offline
                BOREC
                wrote on last edited by
                #7

                I would need a good example code to do that, otherwise I can't do it. I am not that good. :(

                1 Reply Last reply
                0
                • B BOREC

                  I am using VB 2005. trying to create wilcard parameter search. I don't know how to connect variamble Name to the one using in SQL statements. SQL lines in Query builder: SELECT ID, Ime, Priimek, [Službeni telefon], [Službeni GSM], [Domaci telefon], [Privatni GSM], [Elektronska pošta], [Domaci naslov] FROM SLUŽBA WHERE (Priimek LIKE '%' & '@NAME' & '%') And in Form2 I have this code inside button1 object: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim NAME As String NAME = TextBox1.Text Try Me.SLUŽBATableAdapter.FillBy2(Me.TelefonskiImenikDataSet.SLUŽBA, NAME) Catch ex As System.Exception System.Windows.Forms.MessageBox.Show(ex.Message) End Try End Sub can anyone tell me what is wrong here and correct the code, please.I've b een researching a lot and don't find a proper solution. Please Help. The builder doesn't report any error but the button doesn't do a query parameter wildcard search. Variable NAME is underlined with green waveline.It says too many arguments to function FillBy2.

                  L Offline
                  L Offline
                  leckey 0
                  wrote on last edited by
                  #8

                  If no one has mentioned to this you before, please give your message titles meaning.

                  New Poll! Current Rant: "Sally Field Must Die!" http://craptasticnation.blogspot.com/[^]

                  1 Reply Last reply
                  0
                  • B BOREC

                    I am using VB 2005. trying to create wilcard parameter search. I don't know how to connect variamble Name to the one using in SQL statements. SQL lines in Query builder: SELECT ID, Ime, Priimek, [Službeni telefon], [Službeni GSM], [Domaci telefon], [Privatni GSM], [Elektronska pošta], [Domaci naslov] FROM SLUŽBA WHERE (Priimek LIKE '%' & '@NAME' & '%') And in Form2 I have this code inside button1 object: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim NAME As String NAME = TextBox1.Text Try Me.SLUŽBATableAdapter.FillBy2(Me.TelefonskiImenikDataSet.SLUŽBA, NAME) Catch ex As System.Exception System.Windows.Forms.MessageBox.Show(ex.Message) End Try End Sub can anyone tell me what is wrong here and correct the code, please.I've b een researching a lot and don't find a proper solution. Please Help. The builder doesn't report any error but the button doesn't do a query parameter wildcard search. Variable NAME is underlined with green waveline.It says too many arguments to function FillBy2.

                    B Offline
                    B Offline
                    Benny_Lava
                    wrote on last edited by
                    #9

                    Daj cijeli kod. HINT: nemoj radit sa drag & drop nacinom, odnosno koristiti kakve carobnjake kako bi izveo SQL query. Ako hoceš bit dobar programer, onda piši sve iz koda. npr. ja bih to bolje ovako izveo dim dbconn as new system.data.sqlclient.sqlconnection(connectionstring) dim query as string dim sqlKomanda as system.data.sqlclient.sqlcommand() dim reader as system.data.sqlclient.sqldataReader() query = " taj tvoj query" sqlcommand = new sqlcommand(query,dbconn) reader = sqlcommand.executereader() i sada manipuliraš reader objektom i iz njega izvlaciš podatke... itd... Nadam se da sam bio od pomoci. Pozdrav iz Bjelovara.

                    1 Reply Last reply
                    0
                    • B BOREC

                      I am using VB 2005. trying to create wilcard parameter search. I don't know how to connect variamble Name to the one using in SQL statements. SQL lines in Query builder: SELECT ID, Ime, Priimek, [Službeni telefon], [Službeni GSM], [Domaci telefon], [Privatni GSM], [Elektronska pošta], [Domaci naslov] FROM SLUŽBA WHERE (Priimek LIKE '%' & '@NAME' & '%') And in Form2 I have this code inside button1 object: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim NAME As String NAME = TextBox1.Text Try Me.SLUŽBATableAdapter.FillBy2(Me.TelefonskiImenikDataSet.SLUŽBA, NAME) Catch ex As System.Exception System.Windows.Forms.MessageBox.Show(ex.Message) End Try End Sub can anyone tell me what is wrong here and correct the code, please.I've b een researching a lot and don't find a proper solution. Please Help. The builder doesn't report any error but the button doesn't do a query parameter wildcard search. Variable NAME is underlined with green waveline.It says too many arguments to function FillBy2.

                      T Offline
                      T Offline
                      TomGarth
                      wrote on last edited by
                      #10

                      I'm kinda thinkin' you want it to look like this:

                      BOREC wrote:

                      WHERE (Priimek LIKE '''%' & @NAME & '%''')

                      Tom

                      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