select XXXXXx where in Bo


Author
Message
Eric Leissler
Eric Leissler
StrataFrame User (215 reputation)StrataFrame User (215 reputation)StrataFrame User (215 reputation)StrataFrame User (215 reputation)StrataFrame User (215 reputation)StrataFrame User (215 reputation)StrataFrame User (215 reputation)StrataFrame User (215 reputation)StrataFrame User (215 reputation)
Group: StrataFrame Users
Posts: 0, Visits: 527
Hi,

why this code

Me.ActeursBO1.FillDataTable("select * from acteurs where login = " & alltrim(Me.ColorizedTextBox1.Text))

deosn't run 

I have the error
 

column name not valid :'eric'

eric is the  login text   that i wrote in the colorizedtext??

i try  the code

me.acteursBO1.seek(" login = " & me.colorizedtext1.text)

and its dosent  run. its the same error

What i have to do ???

Thanks

Eric

 


Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
The problem is that you are trying to build a command string (which is generally not good practice) and not providing quotes.  You will want to create a parameterized query, otherwise your users can accidentally break your query code (i.e. add a quote in the text box, etc.)

Public Sub FillByLoginName(Byval loginName as String)

    '-- Establish Locals
    Dim cmd As New SqlCommand("SELECT * FROM acteurs WHERE login = @loginName")

    '-- Create the parameters
    cmd.Parameters.AddWIthvalue("@loginName", loginName).SqlDbType = SqlDbType.VarChar

    '-- Execute the query
    me.FillDataTable(cmd)
End Sub

Also, instead of programming queyr logic into a form, you should really create a method, like above, in the BO itself and then pass that over to the BO to execute the query instead of placing that logic in your form.

Eric Leissler
Eric Leissler
StrataFrame User (215 reputation)StrataFrame User (215 reputation)StrataFrame User (215 reputation)StrataFrame User (215 reputation)StrataFrame User (215 reputation)StrataFrame User (215 reputation)StrataFrame User (215 reputation)StrataFrame User (215 reputation)StrataFrame User (215 reputation)
Group: StrataFrame Users
Posts: 0, Visits: 527
thank's

i will try

Eric

Michel Levy
Michel Levy
StrataFrame User (437 reputation)StrataFrame User (437 reputation)StrataFrame User (437 reputation)StrataFrame User (437 reputation)StrataFrame User (437 reputation)StrataFrame User (437 reputation)StrataFrame User (437 reputation)StrataFrame User (437 reputation)StrataFrame User (437 reputation)
Group: StrataFrame Users
Posts: 193, Visits: 9K
Eric,

C'est exactement comme pour le SQL Pass-Through en VFP: il te manque des simples quotes autour de ta valeur alltrim(Me.ColorizedTextBox1.Text).

Comme tu l'as écrit, ta chaine de requete est select * from acteurs where login = eric
alors que tu devrais avoir select * from acteurs where login = 'eric'
donc une requete qui serait

Me.ActeursBO1.FillDataTable("select * from acteurs where login = '" & alltrim(Me.ColorizedTextBox1.Text)) &"'"

Mais il vaut mieux prendre l'habitude des requètes paramétrées comme te le montre Trent

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search