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