0

在我的应用程序中,我必须创建一个包含 2 列和 5 行的表。现在我需要一次更新 5 个值。我有 1 个屏幕,5EditText秒和一个保存Button。单击保存后,5 个编辑框中的值应该在数据库中更新。有人可以帮我查询吗?提前致谢.

我的表结构是:

id    name
1     wee
2     fvfb
3     erer
4     fgfg
5     fggfg

private static final String DATABASE_CREATE =

"create table incomexpense(_id integer primary key autoincrement,"+"price text not null,description text not null,"+"quantity text not null,"+"total text not null,"+"category text not null,"+"recurrence text not null,"+"date text not null,"+"groups text not null);";


private static final String DATABASE_TABLESPIN = "create table spinner(_id primary key autoincrement,"+" spin text not null);";

但是只显示一张桌子??帮帮我..

4

3 回答 3

1

这个类将创建一个表..您可以创建您的必填字段编辑这个类。

public class TableCreater extends SQLiteOpenHelper 
{

    public static final String DATABASE_NAME = "userregister.db";
    public static final int VERSION = 1;

    public static final String TABLE_NAME = "USER_SESSION";

    public static final String COLUMN_ID = "_id";
    public static final String USER_ID = "user_id";

    public static final String TABLE_CREATE =

    "create table " + TABLE_NAME + " (" + COLUMN_ID
            + " integer primary key autoincrement," + USER_ID + " integer);";

    public static final String FIRST_QUERY = "insert into " + TABLE_NAME
            + " (user_id) values(0);";

    public loginchecker(Context context) {
        super(context, DATABASE_NAME, null, VERSION);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(TABLE_CREATE);
        db.execSQL(FIRST_QUERY);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
        Log.w(loginchecker.class.getName(),
                "Upgrading database from version " + oldVersion + " to "
                        + newVersion + ", which will destroy all old data");
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
        onCreate(db);

    }

}

此方法将更新表中的数据..您可以根据需要进行编辑

public InsertingClass InsertID(int uid) 
    {
        ContentValues values = new ContentValues();
        values.put(loginchecker.USER_ID, uid);
        long insertedId = database.insert(loginchecker.TABLE_NAME, null,
                values);
        Cursor cursor = database.query(loginchecker.TABLE_NAME, allColumnsLogin,
                loginchecker.COLUMN_ID + " = " + insertedId, null, null,
                null, null);
        cursor.moveToFirst();
        return cursorToModel(cursor);
    }
于 2012-07-17T07:35:27.307 回答
0

有关创建表,请参阅SQLiteOpenHelper。对于数据库的 crud 操作,请参见ContentProvider

于 2012-07-17T09:16:35.947 回答
0

尝试这个:

public boolean updateValue(long rowId, String useridvalue)
{
    ContentValues args = new ContentValues();
    args.put(USER_ID, useridvalue);
    return db.update(TABLE_NAME, args,
            COLUMN_ID + "=" + rowId, null) > 0;
}
于 2012-07-17T10:24:29.987 回答