The database seems to be less used by game clients in China. I see that it is converted by myself using Excel...
In fact, I always wanted to add a database to the engine, but this is closely related to the game logic, so I didn't do it...
However, it can be determined that the best choice for a database that runs out of the server should be SQLite.
I used it when using. NET as a tool. So I checked and found two solutions:
- SQLite-Net
- Small, a CS file, and a native DLL (C ++ can also be called)
- The interface is clear and easy to understand.
- Supports LINQ. Although small, it has many functions.
- It is equivalent to a packaging of native SQLite c api.
- System. Data. SQLite
- Access through ADO. net
- It can be integrated with vs designer, saving a data editor
- For those who have used ADO. net, they will soon be able to get started.
- If you use another database (such as MySQL) Later, you do not need to change the code.
Create a WPF Data Binding demo for the northwind database:
XHTML code
- <Dockpanel>
- <ListBox name = "listcategory" itemssource = "{binding}" minwidth = "100" selectedindex = "0">
- <ListBox. itemtemplate>
- <Datatemplate>
- <Textblock text = "{binding categoryname}"> </textblock>
- </Datatemplate>
- </ListBox. itemtemplate>
- </ListBox>
- <Stackpanel>
- <Textbox text = "{binding selecteditem. categoryname, elementname = listcategory}"> </textbox>
- <Textbox text = "{binding selecteditem. Description, elementname = listcategory}"> </textbox>
- <Image Source = "{binding selecteditem. Picture, elementname = listcategory}"> </image>
- </Stackpanel>
- </Dockpanel>
If you are pursuing powerful functions and automation, you can select the latter.
The former requires you to define the class corresponding to the table, which is not so convenient, but the code is much simpler:
C-sharp code
- VaR DB = new sqliteconnection ("database/northwind. db3 ");
- VaR result = dB. query <Category> ("select * from categories ");
- This. datacontext = result;
For those who have never been familiar with ADO. net, this direct operation method is better understood.