use text file as a database for creating an images album project in C# language
Автор: ادد المطيري
Загружено: 2022-07-16
Просмотров: 128
List Image Extentions
*.ai; *.bmp; *.gif; *.ico; *.jpeg; *.jpg; *.png; *.ps; *.psd; *.svd; *.tif; *.tiff
How to use txt file as a database in c#
C# Data Access: Text Files
C# - How To Import Text File Data Into Datagridview In C#
how to read, write, process txt file like database in c#
C# resuable library to treat a text file like a
c# - Read line by line from text file and save
How to read from database and write into
How to read data from text file and store in
C# Class: Text file as DataBase
Is a text file a database?
How do you create a text file in a database?
About using text file as database to store data
Use Visual C# to read from and write to a text file
how to read data from text file in c#
C# Class: Text file as DataBase
Renan Rodrigues Duarte
Introduction
I made this class to use on a Mobile Project (.net compact framework). I tried to use SQL Compact but it gets a lot of resources.
This article will try to show you some great features of Classes in C# and to get them you should have some basic knowledge of Csharp.
We are going to create a class that will provide us some pre-made functions to use a simple text file as a Database.
A simple explanation of classes:
"In object-oriented programming, a class is a programming language construct used to group related instance variables and methods.
A method (called a function in some languages) is a set of instructions specific to a class.
Depending on the language, classes may support multiple inheritance or may require interfaces to extend other classes.
A class may indicate either specifically or abstractly what methods exist when the program executes. The latter is known as an 'abstract class'.
A class must be defined with a constructor if used as an object that will be instantiated.
However, some classes, especially those containing factory methods, are defined as static classes with no constructor.
Instead, they merely organize data hierarchically (e.g. the Math class may contain the static constant PI and the static method abs)." (Wikipedia)
Conclusion:
If we are objects, the world would have a class called Persons with many functions and properties that describe us and we would be an object of this class =)
Creating the DataBase
The columns will be separated by ';' and we don't need to set ID reference because we are going to use line number as it.
So, one database with the fields Name, LastName, Phone, Mail and Website would be like:
Copy Code
Notice that We have to set the path and after that we should create a function that gets all the entries and fill another object like a ComboBox, ListView, etc.
P.s.:This should be easily done getting the number of entries DataText.Entries and after using While.
The Engine
All the records can be easily read using FileStream and StreamReader. After reading the line, you only need to split it (using ';' separator).
Then you have an Array with all the values of the line =)
The new entries will be added at the end of the file and to update one line, we will re-write all the database.
That's ok for me because I don't have many records. Otherwise we can save the text in another object which can treat better this problem.
Additional functions
We can set functions with the same name but with different parameters. Like:
Copy Code
public int ReadEntrie(int id, ref string name)
And we are going to get this result:
Many choices
Points of Interest
Setting functions with the same name should be great to get a specific variable variable like, only the name or only the mail.
This code gives you some experience with classes and this would be a start of making dll's and other components =)
I haven't made any bench with this class until now but it should be perfect for small databases.
License
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
source:-
https://www.codeproject.com/Articles/...
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: