1

this code not creating second table please help me......it created first table. only issue with second...i m working in xamarin.android i think it already created a db with one table so i uninstalled my app and tried still no changes.. public Database() {

    }

    public Database(string sqldb_name)
    {
        try
        {
            CreateDatabase(sqldb_name);
        }
        catch (SQLiteException ex) 
        {
            sqldb_message = ex.Message;
        }
    }
    //Gets or sets value depending on database availability
    public bool DatabaseAvailable
    {
        get{ return sqldb_available; }
        set{ sqldb_available = value; }
    }
    //Gets or sets the value for message handling
    public string Message
    {
        get{ return sqldb_message; }
        set{ sqldb_message = value; }
    }
    //Creates a new database which name is given by the parameter
    public void CreateDatabase(string sqldb_name)
    {
        try
        {
            sqldb_message = "";
            string sqldb_location = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
            string sqldb_path = Path.Combine(sqldb_location, sqldb_name);
            bool sqldb_exists = File.Exists(sqldb_path);
            if(!sqldb_exists)
            {
                sqldb = SQLiteDatabase.OpenOrCreateDatabase(sqldb_path,null);
                sqldb_query = sqldb_query = "CREATE TABLE IF NOT EXISTS MyTable(_id INTEGER PRIMARY KEY AUTOINCREMENT,date DATETIME DEFAULT CURRENT_TIMESTAMP, Value INTEGER);";
                sqldb.ExecSQL(sqldb_query);
                sqldb_query = "CREATE TABLE IF NOT EXISTS MyMonth(_id INTEGER PRIMARY KEY AUTOINCREMENT, Month VARCHAR, per INTEGER);";
                sqldb.ExecSQL(sqldb_query);
            }
            else
            {
                sqldb = SQLiteDatabase.OpenDatabase(sqldb_path, null, DatabaseOpenFlags.OpenReadwrite);
                sqldb_message = "Database: " + sqldb_name + " opened";
            }
            sqldb_available=true;
        }
        catch(SQLiteException ex) 
        {
            sqldb_message = ex.Message;
        }
    }
    //Adds a new record with the given parameters
    public void AddRecord(int svalue)
    {

        try
        {

            sqldb_query = "INSERT INTO MyTable(date, Value) VALUES (date() ," + svalue + ");";
            sqldb.ExecSQL(sqldb_query); 
            sqldb_message = "Record saved";
        }
        catch(SQLiteException ex) 
        {
            sqldb_message = ex.Message;
        }
    }

    public void AddRecordPer()
    {
        try
        {


            sqldb_query="INSERT INTO MyMonth(_id,Month,Per) VALUES(1,JAN,10);";

            sqldb.ExecSQL(sqldb_query);
            sqldb_message = "Record saved";
        }
        catch(SQLiteException ex) 
        {
            sqldb_message = ex.Message;
        }
    }

    public Android.Database.ICursor GetRecordCursor()
    {
        Android.Database.ICursor sqldb_cursor = null;
        try
        {
            sqldb_cursor = sqldb.RawQuery("SELECT * FROM MyTable ", null);
            if(!(sqldb_cursor != null))
            {
                sqldb_message =`enter code here` "Record not found";
            }
        }
        catch(SQLiteException ex) 
        {
            sqldb_message = ex.Message;
        }
        return sqldb_cursor;
    }



    public Android.Database.ICursor GetRecordCursor1()
    {
        Android.Database.ICursor sqldb_cursor = null;
        try
        {

            sqldb_cursor = sqldb.RawQuery("SELECT * FROM MyMonth", null);
            if(!(sqldb_cursor != null))
            {
                sqldb_message = "Record not found";
            }
        }
        catch(SQLiteException ex) 
        {
            sqldb_message = ex.Message;
        }
        return sqldb_cursor;
    }

}

}

  • please some one answer me. – Sunita Hiremath Jul 16 '15 at 09:32
  • Please give more information. What's the issue? Do you have an exception while creating the database? If yes, please add it. Have you tried to debug your code? Does it come to execute "create table" statement for the second table? – Grisha Jul 16 '15 at 13:36
  • thank u for replay Grisha..i figured out this issue. it was just db created with out the table i changed db name and installed the app again. it worked.. – Sunita Hiremath Jul 22 '15 at 05:03
  • can u answer me how to save the state of a button even after closing the app please in xamarin.android – Sunita Hiremath Jul 22 '15 at 05:04
  • For this you'd better open another question, since these are unconnected issues. Anyway, if you want to save some parameters after your app is closed, you need to store them in a file or in a database. Probably database will work better for you, since you already use it. Create table for your parameters and insert values to it. – Grisha Jul 22 '15 at 08:49
  • thank u i will try this. can u answer me for this please..http://stackoverflow.com/questions/31555831/set-the-checkbox-if-the-db-table-value-is-1-in-xamarin-android – Sunita Hiremath Jul 22 '15 at 11:24
  • and please make some time and answer me even this.. please help me i badly need this to do..i m fresher so..please.http://stackoverflow.com/questions/31562079/save-the-state-of-button-in-xamarin-android – Sunita Hiremath Jul 22 '15 at 11:43

0 Answers0