• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by PK2011 · Apr 22, 2015 at 04:34 PM · databasesqlitetable

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 t$$anonymous$$s 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();
 
             w$$anonymous$$le (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.

alt text

untitled.jpg (76.5 kB)
Comment

People who like this

0 Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image PK2011 · Apr 23, 2015 at 07:03 AM 0
Share

Thanks Baste.... Here is my full screenalt text

screen.jpg (174.4 kB)

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by bibalexwalid · Apr 15, 2019 at 11:03 AM

Tutorial SQLite Unity3d 2018 or $$anonymous$$gher( 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

https://www.youtube.com/watch?v=dezAuScV9ZY

Comment
walidabazo

People who like this

1 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

how to create table in GUI unity? 2 Answers

Problem with SQLite unity Database 0 Answers

why sqlite can't conneted after build in PC (.exe) 0 Answers

Deleting the main database at runtime. 0 Answers

Sqlite databases getting locked by Unity. 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges