470,636 Members | 1,447 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,636 developers. It's quick & easy.

datasource question

Hi
I would preciate any help on calling for a fuction inside a datasource
string using visual basic.

for example:

I have one function that evaluates some condition in each recordset and
would like to create something like this:
mydatacontrol.recordsource = "select * from mytable where
myfunction(variable)='valor'"

the main idea is to replace all the '' by an 'A', the '' by an 'e' and so
on calling the function

if i use the expression above calling myfunction i get a error
here is my code for myfunction

Public Function myfunction(cadeia As String)
Dim cacentos
Dim sacentos
Dim nciclo As Integer
Dim acento
cacentos = ""
sacentos = "aeiouAEIOUaoAOaeiouAEIOUcCaeiouAEIOU"
For nciclo = 1 To Len(cadeia)
acento = InStr(cacentos, Mid(cadeia, nciclo, 1))
If acento <> 0 Then
cadeia = Left(cadeia, nciclo - 1) & Mid(sacentos, acento, 1) &
Mid(cadeia, nciclo + 1)
End If
Next
myfunction= cadeia
End Function


Jul 19 '05 #1
7 2033
Wow, how many languages do you speak? Portuguese? German? Spanish?
Italian?

This isn't a classic ASP issue, as indicated by your code. I almost follow
what you're saying, and if I do:

mydatacontrol.recordsource = "select * from mytable where " &
myfunction(variable) & "='valor'"

Ray at work

"news.microsoft.com" <no**@hotmail.com> wrote in message
news:eI**************@TK2MSFTNGP09.phx.gbl...
Hi
I would preciate any help on calling for a fuction inside a datasource
string using visual basic.

for example:

I have one function that evaluates some condition in each recordset and
would like to create something like this:
mydatacontrol.recordsource = "select * from mytable where
myfunction(variable)='valor'"

the main idea is to replace all the '' by an 'A', the '' by an 'e' and so on calling the function

if i use the expression above calling myfunction i get a error
here is my code for myfunction

Public Function myfunction(cadeia As String)
Dim cacentos
Dim sacentos
Dim nciclo As Integer
Dim acento
cacentos = ""
sacentos = "aeiouAEIOUaoAOaeiouAEIOUcCaeiouAEIOU"
For nciclo = 1 To Len(cadeia)
acento = InStr(cacentos, Mid(cadeia, nciclo, 1))
If acento <> 0 Then
cadeia = Left(cadeia, nciclo - 1) & Mid(sacentos, acento, 1) &
Mid(cadeia, nciclo + 1)
End If
Next
myfunction= cadeia
End Function

Jul 19 '05 #2
That will not evaluate each record.
I should write record instead of value
Thanks anyway

"Ray at <%=sLocation%>" <myfirstname at lane34 dot com> escreveu na mensagem
news:u6****************@tk2msftngp13.phx.gbl...
Wow, how many languages do you speak? Portuguese? German? Spanish?
Italian?

This isn't a classic ASP issue, as indicated by your code. I almost follow what you're saying, and if I do:

mydatacontrol.recordsource = "select * from mytable where " &
myfunction(variable) & "='valor'"

Ray at work

"news.microsoft.com" <no**@hotmail.com> wrote in message
news:eI**************@TK2MSFTNGP09.phx.gbl...
Hi
I would preciate any help on calling for a fuction inside a datasource
string using visual basic.

for example:

I have one function that evaluates some condition in each recordset and
would like to create something like this:
mydatacontrol.recordsource = "select * from mytable where
myfunction(variable)='valor'"

the main idea is to replace all the '' by an 'A', the '' by an 'e' and

so
on calling the function

if i use the expression above calling myfunction i get a error
here is my code for myfunction

Public Function myfunction(cadeia As String)
Dim cacentos
Dim sacentos
Dim nciclo As Integer
Dim acento
cacentos = ""
sacentos = "aeiouAEIOUaoAOaeiouAEIOUcCaeiouAEIOU"
For nciclo = 1 To Len(cadeia)
acento = InStr(cacentos, Mid(cadeia, nciclo, 1))
If acento <> 0 Then
cadeia = Left(cadeia, nciclo - 1) & Mid(sacentos, acento, 1) &
Mid(cadeia, nciclo + 1)
End If
Next
myfunction= cadeia
End Function


Jul 19 '05 #3

reformulating example :

mydatacontrol.recordsource = "select * from mytable where
myfunction(recordset.field)='valor'"
Jul 19 '05 #4
Hello,

We can have the usedr defined function "myfunction" in the query string
directly. The query string will be send to database and database can't
recognize it. If your database is SQL server 2000, you may define a UDF in
the database to take place the function. If not, you may change your query
to:

mydatacontrol.recordsource = "select * from mytable where fieldname='vlr'"

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Jul 19 '05 #5
"news.microsoft.com" <no**@hotmail.com> wrote in message
news:er*************@TK2MSFTNGP10.phx.gbl...

reformulating example :

mydatacontrol.recordsource = "select * from mytable where
myfunction(recordset.field)='valor'"


[SQL Server 2000]
SELECT * FROM mytable WHERE myfield = 'valor'
COLLATE SQL_Latin1_General_Cp850_CI_AI

[Access/SQL Server 7]
SELECT * FROM mytable WHERE myfield LIKE 'v[a]l[o]r'

In the future please indicate which database and version you are using.
If you are using SQL Server 2000, there is a topic on the COLLATE clause
in Books Online(BOL).

HTH
-Chris Hohmann


Jul 19 '05 #6
My previous post may be too brief on SQL server UDF and I should to address
more on it:

SQL User-Defined Functions allow you to define your own Transact-SQL
functions using the CREATE FUNCTION statement. It take zero or more input
parameters, and return a single value. Some user-defined functions return a
single, scalar data value, such as an int, char, or decimal value. For more
information on Sql server UDF, you may refer to:

Microsoft SQL Server 2000 User Defined Functions Whitepaper
http://support.microsoft.com/default...l%2fcontent%2f
2000papers%2fUser_defined_functions.asp

If you find that UDF's are not a solution for you, , you may refer to
Chris's suggestion. It is also a wonderful solution for this issue. Thank
for Chirs!

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Jul 19 '05 #7
Hollo!
Jul 19 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Stephen | last post: by
7 posts views Thread by bernadou | last post: by
1 post views Thread by AJ | last post: by
7 posts views Thread by ThunderMusic | last post: by
1 post views Thread by WhiteWizard | last post: by
1 post views Thread by Korara | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.