- Home /
How to connect my Application to SQLite Database?
Hi all,
Am new to Unity development. My simple question is how to connect to database in Unity. I followed http://answers.unity3d.com/questions/743400/database-sqlite-setup-for-unity.html this page and successfully connected to database. But I had been thrown out by an error "SqliteSyntaxException: no such table". Here goes my code and since am new to development my code is not in proper arrangement.
Excuse for Typos / grammar mistake. Thanks in advance.
using UnityEngine;
using System.Collections.Generic;
using System;
using System.Data;
using System.Data.SqlClient;
using Mono.Data.SqliteClient;
public class Students : MonoBehaviour
{
//Variables
string connectionString = "URI=file:Database.db";
string commandString = "Select ID,Name from Stud";
SqliteConnection Conn;
SqliteCommand Command;
void Start()
{
Display ();
}
void OnGUI ()
{
//GUI Code goes here
}
void Display()
{
Conn = new SqliteConnection (connectionString);
try
{
Conn.Open ();
Command = new SqliteCommand (commandString, Conn);
SqliteDataReader DR = Command.ExecuteReader();
while (DR.Read())
{
int ID = DR.GetInt32(0);
string Name = DR.GetString(1);
Debug.Log("ID = " +ID+ "Name = "+Name);
}
}
catch (NullReferenceException ex)
{
print (ex);
}
catch (ArgumentException ab)
{
print (ab);
}
}
}
My Database name : Database Table Name : Stud Two fields : ID and Name.
Answer by bibalexwalid · Apr 15, 2019 at 11:03 AM
Tutorial SQLite Unity3d 2018 or higher( Android , Windows Phone , Windows , IOS, WINRT ) How to Connection Database Sqlite how to Create Table , Select , Insert , Update , Delete , Search
How to read data from on unity Solving all error in unity for assembly reference:
1- error "The type or namespace name Data' does not exist in the namespace 'Mono'. Are you missing an assembly reference?"
2- and error "The type or namespace name MONO' does not exist in the namespace Data'. Are you missing an assembly reference?"
using Mono.Data.Sqlite;
using System;
using System.Data;
using System.IO;
using UnityEngine.UI;
learning how:
SQLite Admin to create database and tables .......
SQLite DLL to support unity .s3db extension and compile on unity for windows 32bit or 64bit.
Github example :
https://github.com/walidabazo/SQLiteUnity3d_Android
Video
Your answer
Follow this Question
Related Questions
how to create table in GUI unity? 2 Answers
SQLite Transaction Update Problem on Android 0 Answers
SQLite Except: The database file is locked 1 Answer
Database (SQLite) Setup for Unity 0 Answers
Retrieving data from Sqlite database using Mono.Data.Sqlite 0 Answers