Using flatfile (aka txt or xml) as database
So here's the short of it.
I made a program that allows users to call a program based on a code they set.
I have 2 input textbox types.
textbox2 is for the code they wish to assign to the program.
textbox3 is the path to the file
When they type in type in textbox1 and hit enter, it calls the program to run if it matches textbox2 value.
I have searched high and low and have not been able to find a definitive answer to what I am looking for.
I want the user to have an unlimited amount of programs they can launch so I need a database of sorts. I want to set it up so that when a user types in the new code in textbox2 and the corresponding directory relation in textbox3, it will save it to a file for my program to access and use as a database whenever they open my program.
Right now, I have 40 text boxes on the code/program form. This only gives the user the ability to store up to 20 codes of their own. I am using My.Settings to store this information, but it just doesn't seem to give me the ability to "add on the fly". Meaning I have to physically designate each text box it's My.Settings relation.
The code is then executed after a match between textbox1 and textbox2.
My code is set up like this:
If Me.textbox1.text = My.Settings.Settings1 then call My.Settings.Settings2
and so on.
This makes for a very big file if I were to expand it, not to mention more textboxes than Windows Vista has total! :)
I need an efficient and effective way to store this information after hitting save on form2, it will append the user input to a file. And when the form1 loads it will load the xml (lets say for example) and the user types in a code then the program will search through the loaded XML file if that command exists and if it does then to call the corresponding program attached to it.
I have been racking my brains on this. Burning up Google and skimmed through my entire VB.NET 2008 book to no avail.
One other thing. I don't even know if this warrants mentioning since I get the gist of the file system, but this file (XML file) will be located in only one spot (Documents) on the users HD.
Any help would be GLADLY appreciated!
Thanks for your time!
Re: Using flatfile (aka txt or xml) as database
Quote:
Originally Posted by
whattan00b
My code is set up like this:
If Me.textbox1.text = My.Settings.Settings1 then call My.Settings.Settings2
...VB.NET 2008 ...
Thread moved from 'VB6 and Earlier' forum to 'VB.Net' (VB2002 and later) forum
Re: Using flatfile (aka txt or xml) as database
If you "need a database of sorts" then why not use an actual database rather than attempt this with a flat file?
Re: Using flatfile (aka txt or xml) as database
I want to keep it simple for the users. I don't want them to have to install MySQL or have it reference any sort of online DB. I want to keep it consolidated to the program itself.
Re: Using flatfile (aka txt or xml) as database
Then use a file-based database like Compact SQL Server, SQLite, or even Microsoft Access. None of which need any server installation and all are self-contained.
Re: Using flatfile (aka txt or xml) as database
Access would require Office to be installed. (If I'm correct.)
Is there a solution you can offer me based on this information?
Re: Using flatfile (aka txt or xml) as database
No, Access is based off Microsoft JET. the database it makes is a JET database, and all modern versions of Windows can read a JET database via OleDB or ODBC. Access is just a program that lets you build, manipulate and do other things with it. You don't need Office installed to get a .NET or any other program to talk to a JET database, but for editing it directly, it sure is nice.
Re: Using flatfile (aka txt or xml) as database
Quite interesting! I learned something new today! So, that being said, how is this accomplished? I use Visual Studio.NET 2008.
Re: Using flatfile (aka txt or xml) as database
Admins or Mods, please move this post to the Database section as I see I have posted in the incorrect forum, thereby lessening my chances of getting a solution to my problem.
I do apologize for this. :blush:
Re: Using flatfile (aka txt or xml) as database
Just do a search on the forums for "connecting to an Access database". The terms "Access" and "JET database" are used somewhat synonymously.
In a nutshell though you'd make an OLEDB connection object:
Code:
Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=;")
con.Open
Then make either a Command or DataAdapter, depending on your need:
Code:
Dim cmd As New OleDbCommand("SELECT * FROM table1;", con)
Then execute a reader to read it, or just execute the statement to make it happen:
Code:
Dim reader As OleDbDataReader = cmd.ExecuteReader()
While reader.Read
myString = reader.Item("column1").ToString
End While
reader.Close
And finally clean up:
Code:
con.Close
cmd.Dispose
con.Dispose
Re: Using flatfile (aka txt or xml) as database
Thanks for your reply! I wasn't sure I would get one considering I posted in the wrong place. Thank you!
Re: Using flatfile (aka txt or xml) as database
Quote:
Originally Posted by
whattan00b
Admins or Mods, please move this post to the Database section as I see I have posted in the incorrect forum,
It was the right forum to start with, but now things have changed a bit the DB forum is more apt - thread moved.
Note that there is lots of useful info on this kind of topic in our Database Development FAQs/Tutorials (at the top of this forum), particularly the ADO.Net tutorial.
Re: Using flatfile (aka txt or xml) as database
hehe thanks!
I will try it again later. I'm so exhausted from trying to figure it out lol.
I'll keep updated if I have further issues. Thank you all for the replies! :D