Search Unity

query on database

Discussion in 'Scripting' started by Hippiecode, Sep 17, 2014.

  1. Hippiecode

    Hippiecode

    Joined:
    Feb 13, 2012
    Posts:
    110
    hi to all....,
    i wrote like dis to get "subject name" from my database.cs. I got good result in pc.Now i hav a problem with android.In android i didn't get my "subject name".Plz help me...
    My code is lik dis.
    Code (CSharp):
    1. void subjectlist(string p){
    2.  
    3.         string connectionString = "URI=file:"+Application.persistentDataPath+"/"+p;    
    4.  
    5.         dbcon = new SqliteConnection(connectionString);
    6.         dbcon.Open();    
    7.         dbcmd = dbcon.CreateCommand();    
    8.         string sql="select distinct subject_name  from topicmaster ORDER BY subject_id";
    9.         int count=0;
    10.         dbcmd.CommandText = sql;
    11.         reader = dbcmd.ExecuteReader();
    12.         while(reader.Read()) {
    13.                 subjectList[count]=reader.GetString(0);
    14.                 count++;
    15.             }
    16.         Array.Resize(ref subjectList,count);
     
    Last edited: Sep 19, 2014
  2. Krysalgir

    Krysalgir

    Joined:
    Aug 30, 2010
    Posts:
    95
    And what kind of error do you get?
    Nothing, a crash ?
    You forgot to add the var declaration in your piece of code, I guess global vars declared earlier in the file.

    Also, could you use the code flags to get some more easily readable text ? :)
     
  3. Hippiecode

    Hippiecode

    Joined:
    Feb 13, 2012
    Posts:
    110
    "SqliteSyntaxException: no such table: topicmaster"
    i got above error
     
  4. Krysalgir

    Krysalgir

    Joined:
    Aug 30, 2010
    Posts:
    95
    Looks more like a pure SQL error rather than a C#/Unity one.
    Are you sure your connexion is correctly done? And that your database is the good one as well?
     
  5. Limeoats

    Limeoats

    Joined:
    Aug 6, 2014
    Posts:
    104
    Hi ganesh.

    Your code is syntactically correct. This means that there are only a few reasons that you'd be getting this error.

    • Are you sure that the table name is topicmaster?
    • Are you sure that "p" being passed in has the correct name of the database? It needs to contain the actual name of the database for it to work. For example: If your database name was "mydatabase.db", your connection string line would have to look like this
      Code (CSharp):
      1. string connectionString = "URI=file:"+Application.persistentDataPath+"/" + "mydatabase.db";
      Make sure the variable "p" being passed into the function holds the name of the database like in my example above.
    Also, on a side note, please use code tags when posting segments of code.
    http://forum.unity3d.com/threads/using-code-tags-properly.143875/
     
  6. Hippiecode

    Hippiecode

    Joined:
    Feb 13, 2012
    Posts:
    110
    yes my table name is topic master,its works in pc well.i hav a problem in android