Unity数据读取与存储_数据库SQLite

Unity数据读取与存储_数据库SQLite
摘要由CSDN通过智能技术生成

什么是SQLite

1. SQLite是一款轻型的数据库


2. SQLite的设计目标是嵌入式的


3. SQLite占用资源非常的低


4. SQLite能够支持Windows/Linux/Unix等等主流的操作系统

准备工作

安装SQLiteManager

在Unity中导入

Mono.Data.Sqlite.dll

sqlite3.dll

System.Data.dll

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mono.Data.Sqlite;
using System;
using UnityEngine.UI;

public class StudentManager : MonoBehaviour {
    //输出文字
    public Text UItext;
    //数据库地址
    string path;
    //连接
    public SqliteConnection connection;
    //命令行
    public SqliteCommand command;
    //数据库操作类
    public SqliteDataReader reader;

	// Use this for initialization
	void Start () {
        //初始化地址
        path = "Data source = " + Application.dataPath + "/Student.sqlite";
        //创建连接
        connection = new SqliteConnection(path);
    }
    //OnGUI按钮
    private void OnGUI()
    {
        if (GUILayout.Button("           创建          "))
        {
            CreateDataBase();
            //关闭数据库
            Dispose();
        }
        if (GUILayout.Button("           添加           "))
        {
            Dispose();
            AddStudent();
            //关闭数据库
            Dispose();
        }
        if (GUILayout.Button("           查询           "))
        {
            Dispose();
            UItext.text = SelectStudent();
            //关闭数据库
            Dispose();

        }

        if (GUILayout.Button("           查询 2          "))
        {
            Dispose();
            UItext.text = SelectStudent2();
            //
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值