Free dll to work with Access database
Collapse
X
-
Thanks Bule, that got me on the right track. This seems to work good.
Code:function xMDBQueryToTable(db, Query) if db ~= "" then if File.DoesExist(db) then if Query ~= "" then --define variables: local Rows=0; local Columns=0; local ColumnNames={}; local Data={}; result = DLL.CallFunction(_SourceFolder.."\\AutoPlay\\Docs\\xMDB.dll", "Query_Select_MDB", "\""..db.."\",\""..Query.."\"", DLL_RETURN_TYPE_STRING, DLL_CALL_STDCALL) if String.Left(result, 5) ~= "Error" then if result ~= "NO_DATA" then -- Get all the rows returned tbl = DelimitedStringToTable(result, "|") if tbl then -- Get column names from first row tblCols = DelimitedStringToTable(tbl[1], ";") if tblCols then -- Loop through the columns for nCol=1, Table.Count(tblCols) do Columns = Columns + 1 ColumnNames[Columns]=tblCols[nCol]; end end --Get the data for nRow = 2, Table.Count(tbl) do Rows = Rows + 1 Data[Rows]={}; tblRow = DelimitedStringToTable(tbl[nRow], ";") if tblRow then for nCol = 1, Table.Count(tblRow) do Data[Rows][ColumnNames[nCol]]=tblRow[nCol] end end end tbl = nil tblCols = nil tblRow = nil return {Rows=Rows,Columns=Columns,ColumnNames=ColumnNames,Data=Data}; end else Progress.SetVisible("Prog", false) Dialog.Message("No Data", "No records returned.", MB_OK, MB_ICONINFORMATION) end else Dialog.Message("Failed", result, MB_OK, MB_ICONEXCLAMATION) return "Error" end else Dialog.Message("No Query", "Please enter an select query", MB_OK, MB_ICONEXCLAMATION) return "Error" end end else Dialog.Message("No Database", "Please select a database first", MB_OK, MB_ICONEXCLAMATION) return "Error" end end
Dermot
I am so out of here :yes
Comment
-
-
Nice.. :yes
If I may sugest using Lua, you couldt use the ODBC driver from LuaSQL
That way you could actually just take the function Bule made for the MySQL version of this and use it directly as I understand it.
Havent tried it though but the LuaSQL also has drivers for Oracle and JDBC
so the incorporation would be huge if you just had to call the right driver and reuse the functions.
You can also find a refinde version of Bules function at:
As I saied, just a surgestion.. havent tried it.
But again I like what you did Dermot, It looks great (havent testet that either yet..) and just will writting this post I have allready come up with a few apps where it would be handy.
I do have a question. does can it use a database that was created in Access? using linked tables from a SharePoint Server? I that case the Dll you made is a very powefull tool that give access to all the functions of MS Access, you couldt even use the report generater in access to print reports from the database... Did a project doing this a while back, but couldent control the data from AMS so I had to put the data in the database manually and then put the database in my AMS project to use the reports.
by using a commandline arg for access.
I'm rambling on now so I think I'll stop here before I get in to deep...
Cheers,
Jonas
Comment
-
-
@ Bule
Yes maybe I didn't use the best delimiters but they can be changed very easily. What I might do is add them as parameters when calling the dll. That way the user can use what ever they want
@ Jonas DK
If I may sugest using Lua, you couldt use the ODBC driver from LuaSQL
I do have a question. does can it use a database that was created in Access? using linked tables from a SharePoint Server?
you couldt even use the report generater in access to print reports from the databaseDermot
I am so out of here :yes
Comment
-
-
New version available. Use the links in the first post.
Changed the delimiters a little so that you should not run into problems if the delimeters are in the data.
Column delimeter is ";;"
Row delimeter is "||"
I have also included an updated example which includes a function to take the results from a select query and create a lua table just like the SQLiteQueryToTable function does.Dermot
I am so out of here :yes
Comment
-
-
how can i save and delete data from the DB???
i have a input1 and input2 how can i save the text in the input1 and input2 to the DB and how can i delete a data (or row) from the DB???
Add data from Inputs to db.
Code:FirstName = Input.GetText("Input1") LastName = Input.GetText("Input2") INSERT IGNORE INTO Contacts(FirstName, LastName) VALUES('"..FirstName.."','"..LastName.."'")
Code:FirstName = Input.GetText("Input1") LastName = Input.GetText("Input2") DELETE FROM Contacts WHERE FIrstName = '"..FirstName.."' AND LastName = '"..LastName.."'"
Dermot
I am so out of here :yes
Comment
-
-
i need the name of the "DLL.CallFunction" to call the Function
i need the name of the "CallFunction" to call the Function to save and name of the Function to delete. or if you can give me Example in file to save and delete data from input object. PLZ
i need to save more then 1000 words can i yus thex text table???Last edited by lnd; 05-18-2007, 12:15 AM.
Comment
-
-
The sample app as what you need.
Add a new record:
DB = "Path to your Access database"
FirstName = Input.GetText("Input1")
LastName = Input.GetText("Input2")
Query = "INSERT IGNORE INTO Contacts(FirstName, LastName) VALUES('"..FirstName.."','"..LastName.."'")"
result = DLL.CallFunction(_SourceFolder.."\\AutoPlay\\Docs\ \xMDB.dll", "Query_Update_MDB", "\""..DB.."\",\""..Query.."\"", DLL_RETURN_TYPE_STRING, DLL_CALL_STDCALL)
if result == "OK" then
Dialog.Message("Success", "Record added.", MB_OK, MB_ICONINFORMATION)
else
Dialog.Message("Failed", result, MB_OK, MB_ICONEXCLAMATION)
end
DB = "Path to your Access database"
FirstName = Input.GetText("Input1")
LastName = Input.GetText("Input2")
Query = "DELETE FROM Contacts WHERE FIrstName = '"..FirstName.."' AND LastName = '"..LastName.."'""
result = DLL.CallFunction(_SourceFolder.."\\AutoPlay\\Docs\ \xMDB.dll", "Query_Update_MDB", "\""..DB.."\",\""..Query.."\"", DLL_RETURN_TYPE_STRING, DLL_CALL_STDCALL)
if result == "OK" then
Dialog.Message("Success", "Record deleted.", MB_OK, MB_ICONINFORMATION)
else
Dialog.Message("Failed", result, MB_OK, MB_ICONEXCLAMATION)
endi need to save more then 1000 words can i yus thex text table???Last edited by Dermot; 05-18-2007, 12:28 AM.Dermot
I am so out of here :yes
Comment
-
-
Originally posted by lnd View Posti need to save "1000 words in one field" PLZ give me example in AMS file PLZ to save and delete data from the databaseDermot
I am so out of here :yes
Comment
-
Comment