任何人都可以帮助我,请问我上周被困在这里了吗? [英] Can anyone help me out please I im stuck here from last week ?

查看:84
本文介绍了任何人都可以帮助我,请问我上周被困在这里了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

below is my SqliteHelper class and I want to create a table and initialize it with two columns first ID and second names like a real attendance register and I want to add columns of attendanceStatus on button click in java file like everyday I want to save attendance in that table(add a column per day) please give me some hint how to achieve this else i'll do on my own!





我尝试了什么:





What I have tried:

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import java.text.DateFormat;
import java.util.Calendar;

public class SqliteHelper extends SQLiteOpenHelper {

    Calendar calendar;

    public static final String DATABASE_NAME = "attendanceDatabase.db";
    public static final String TABLE_NAME = "studentAttendance";
    public static final String COL_1 = "ID";
    public static final String COL_2 = "NAMES";
    public static String COL_3;
    public static int DATABASE_VERSION = 1;

    public SqliteHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);

    }

    @Override
    public void onCreate(SQLiteDatabase db) {

        final String CREATE_TABLE =
                " CREATE TABLE " + TABLE_NAME + "("
                        + COL_1 + " INTEGER PRIMARY KEY AUTOINCREMENT ,"
                        + COL_2 + " TEXT "
                        + ")";

        db.execSQL(CREATE_TABLE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

        calendar = Calendar.getInstance();
        COL_3 = DateFormat.getDateInstance(DateFormat.FULL).format(calendar.getTime());

        db.execSQL(" ALTER TABLE " + TABLE_NAME + " ADD COLUMN " + COL_3 + " TEXT ");
        onCreate(db);
    }

    /*public Boolean insertAttendance(){

    }*/
}
above is my SqliteHelper class and I want to

推荐答案

如果你想在每个出勤日都有一个专栏,你将需要提前计划并找出你需要的数量;稍后添加它们,一次一个,是不切实际的。



您可以将所有出勤数据作为字符串存储在一列中作为替代;例如YYYYNYYYYN ......或Y,Y,Y,Y,N,......
If you want a column for every "attendance day" you will have to plan ahead and figure out how many you need; adding them later, one at a time, is not practical.

You could store all the attendance figures as a "string" in a single column as an alternative; e.g. "YYYYNYYYYN...." or "Y,Y,Y,Y,N,.."


这篇关于任何人都可以帮助我,请问我上周被困在这里了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆