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.