|
-
Aug 13th, 2003, 04:13 AM
#1
Thread Starter
Junior Member
Calling a stored function
Hi,
Because the VBA function replace isn't accessible with the ole db Jet Provider in vb.net, I've made a module in my (Acces)database wich contains a function that returns the same value as replace does:
Function gReplace(strIn As String, strFind As String, strReplace As String) As String
gReplace = Replace(strIn, strFind, strReplace)
End Function
Now I would like to call this function in an updatequery from vb.net looking like this:
adapter.UpdateCommand.CommandText="UPDATE Crawford_nl
SET Phonenr= gReplace(Phonenr, '/', '')"
But when I execute the command I get the error: "Undefined function gReplace in expression".
And when I add this code:
adapter.UpdateCommand.CommandType=CommandType.StoredProcedure
I get the error: "Expected query name after EXECUTE"
Can anyone help me with this problem?
-
Aug 13th, 2003, 06:45 AM
#2
Sleep mode
Is gReplace Function declared as Public ??
-
Aug 13th, 2003, 07:26 AM
#3
Thread Starter
Junior Member
It wasn't declared public, but after trying that, I still get the same error.
-
Aug 13th, 2003, 07:32 AM
#4
Sleep mode
Try to use VisualBasic namespace at the very top of the module file .
-
Aug 13th, 2003, 07:50 AM
#5
Thread Starter
Junior Member
Could you give me some advice on how to do that, I have not worked much with namespaces yet.
-
Aug 13th, 2003, 07:54 AM
#6
Sleep mode
Simply , just use this in the module :
VB Code:
Imports Microsoft.VisualBasic
-
Aug 13th, 2003, 08:09 AM
#7
Thread Starter
Junior Member
The intellisence engine does not regognize the keyword,
Imports ...
When I put that line in my code, I can't even use the function anymore in Acces.
-
Aug 13th, 2003, 08:17 AM
#8
Sleep mode
Originally posted by Bmxpert
The intellisence engine does not regognize the keyword,
Imports ...
When I put that line in my code, I can't even use the function anymore in Acces.
How come it doesn't recognize it ? Are you sure ,you're using VB.NET and put that line at very top of the module?
-
Aug 13th, 2003, 08:34 AM
#9
Thread Starter
Junior Member
I'm using vb.net to open the database and to update it. But the function gReplace is a user defined function I wrote in a module in the database in Acces2003 and there the line: "Imports Microsoft.VisualBasic" is not recognized.
Or did you mean that I had to put that line a the top of my vb.net code? When I do that it is obviously recognized but there is still not much happening (read: "I get the same errors")
-
Aug 13th, 2003, 08:41 AM
#10
Sleep mode
Yeah , I meant to put that import statement in vb.net IDE code . Anyways , if you are getting the error in this line , try this .
VB Code:
adapter.UpdateCommand.CommandText="UPDATE Crawford_nl
SET Phonenr=" & gReplace(Phonenr, '/', '')
-
Aug 13th, 2003, 09:00 AM
#11
Thread Starter
Junior Member
Don't take this the wrong way, but I think we're not on the same frequency. I'll try to clarify what my problem is. In Acces you can make updatequeries such as:
UPDATE Crawford_nl
SET Phonenr= Replace(Phonenr, '/', '')"
The Replace function is unfortunately not available when trying to execute this query in VB.NET because the Provider (Microsoft Jet 4.0 OLE DB Provider) does not support this. After searching on the net, I've discovered that some people have encountered the same problem. A solution someone suggested was to write a wrapper function in the Accesdatabase wich returns the same result as the replace function, and to call this function in the query. Wich means that VB.NET has no knowledge of the existance of this function. So the commandtext of the updatecommand has to be a string containing the full query(see above). I hope this makes things more clear and btw, thanx for your help.
-
Aug 13th, 2003, 09:14 AM
#12
Sleep mode
I was a little confused because the Replace Function which exists in two different namespaces (or classes): 1- in the VisualBasic 2-in the String . So I was paying attention to this abviously . Sorry dude I've never worked on this thing . I mean , I've worked with ADO.NET and updating stuff but not like what you're doing . It's so easy . But , can't you use one of these to solve the problem ?
-
Aug 13th, 2003, 09:59 AM
#13
If your query in Access uses the Access function you made then you should be able to call it by name some what like you would a stored procedure in SQL. Then it should use any native Access functions of Access user functions. (I think this is true anyway) If you are trying to write out the query text in vb.net then you don't need the native Access functions you can use the VB.NET functions to perform the same task.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|