简体   繁体   English

我应该为用户信息数据库使用什么类型的数组? vb.net

[英]What type of array should I use for a database of information about the user? vb.net

So I'm trying to make a system where a person can input data about different people and I want to store it in a textile to search and sort the data, It would contain first name, surname, location, phone number.所以我试图建立一个系统,一个人可以输入关于不同人的数据,我想把它存储在纺织品中以搜索和排序数据,它会包含名字、姓氏、位置、电话号码。

If I were to use a 2d array how would I go about inputting the data through a loop instead of just writing it out myself.如果我要使用二维数组,我 go 如何通过循环输入数据而不是自己写出来。

Or I could use one dimensional arrays and store each type of data, first name, surname etc in separate text files but I am not sure if that would work/be efficient.或者我可以使用一维 arrays 并将每种类型的数据、名字、姓氏等存储在单独的文本文件中,但我不确定这是否可行/是否有效。

If you stored the data as JSON, it would be easier to maintain.如果将数据存储为 JSON,则更易于维护。

You would create a class to represent the data, read in the file, parse the contents to a collection of your class, and then use LINQ to do your filtering.您将创建一个 class 来表示数据,读取文件,将内容解析为 class 的集合,然后使用 LINQ 进行过滤。

This would be efficient enough if you aren't doing any inserts/updates, in which case I would recommend moving to a database to handle these.如果您不进行任何插入/更新,这将足够有效,在这种情况下,我建议您移至数据库来处理这些操作。 You could still use the same approach and just serialize the JSON collection back to the file, but you would start to see some significant slow down of the write operation pretty quickly.仍然可以使用相同的方法,只需将 JSON 集合序列化回文件,但您会很快发现写操作速度明显变慢。

Here is an example of defining the class:以下是定义 class 的示例:

Public Class Person
    <JsonProperty("firstName")>
    Public Property FirstName As String

    <JsonProperty("surname")>
    Public Property Surname As String

    <JsonProperty("location")>
    Public Property Location As String

    <JsonProperty("phoneNumber")>
    Public Property PhoneNumber As String

End Class

Here is an example of reading a text file and parsing it to a collection of your class:以下是读取文本文件并将其解析为您的 class 集合的示例:

Public Function GetPeople(path As String) As IEnumerable(Of Person)
    Dim literal = IO.File.ReadAllText(path)
    Dim people = JsonConverter.DeserializeObject(Of IEnumerable(Of Person))(literal)

    Return people
End Function

Here is an example of adding people to the collection and serializing it back to the file:这是将人员添加到集合并将其序列化回文件的示例:

Public Function AddPerson(path As String, record As Person) As IEnumerable(Of Person)
    Dim people = GetPeople(path).ToList()
    people.Add(record)
    IO.File.WriteAllText(path, people.ToString())
    Return people
End Function

Keep in mind you'd want to add exception handling and business logic to check that the state is what you would expect it to be.请记住,您需要添加异常处理和业务逻辑来检查 state 是否符合您的预期。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在vb.net中我应该使用什么代替Oftype? - what should i use instead of Oftype in vb.net? VB.NET我应该为此使用集合吗? - VB.NET Should I use a collection for this? VB.Net是否应将数据库连接字符串与应用程序或用户范围一起存储? - VB.Net Should I Store Database Connection String with Application or User Scope? 我应该在VB.Net中使用哪种技术来制作2D图形? WPF,DirectX,SlimDX? - What technology should I use for 2d graphics in VB.Net? WPF, DirectX, SlimDX? 我应该为vb.net应用程序使用什么SQL查询语句? - what sql query statement should i use for a vb.net application? 我应该使用什么可编辑控件在vb.net应用程序中显示电子表格? - what editable control should i use to display my spreadsheet in a vb.net application? 在列表框中显示数据库信息 vb.net - Show information of database in a listbox vb.net 我可以使用什么作为List的通用,所以我可以在vb.net中更改列表中的类型 - what can i use as a generic of List so i can change the type within the list in vb.net VB.NET反序列化/应该使用哪种模式? - VB.NET deserialization / Which pattern should i use? 在 VB.NET 为什么我应该使用 Select 而不是 If? - In VB.NET why should I use Select, instead of If?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM