我遇到这样的问题:
我有新客户的注册表,但他填写了所有字段,如登录,密码等。 Base SQL中没有任何事情发生。
我不明白我的错误。
switch (v.getId()) {
case R.id.create_account:
database = dbHelper.getWritableDatabase();
contentValues = new ContentValues();
// AlertDialog Registration
View viewInflated = LayoutInflater.from(this).inflate(R.layout.registration_form, (ViewGroup) findViewById(android.R.id.content), false);
inputPassword = (EditText) viewInflated.findViewById(R.id.input_password);
inputLogin = (EditText) viewInflated.findViewById(R.id.input_login);
inputEmail = (EditText) viewInflated.findViewById(R.id.input_email);
builder.setView(viewInflated);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String login = inputLogin.getText().toString();
String email = inputEmail.getText().toString();
String password = inputPassword.getText().toString();
// Передаем с помошью КонтентВелью наши значения из полей
contentValues.put(DBHelper.KEY_NAME, login);
contentValues.put(DBHelper.KEY_EMAIL, email);
contentValues.put(DBHelper.KEY_PASSWORD, password);
// Записываем в базу ТейблКонтакты
database.insert(DBHelper.TABLE_CONTACTS, null, contentValues);
database.close();
Toast toast = Toast.makeText(getApplicationContext(), "Вы зарегистрированы", Toast.LENGTH_LONG);
toast.show();
dialog.cancel();
}
});
我的DBHelper
public class DBHelper extends SQLiteOpenHelper {
public static final int DATABASE_VERSION = 1;
public static final String DATABASE_NAME = "contactDb";
public static final String TABLE_CONTACTS = "contacts";
public static final String KEY_ID = "_id";
public static final String KEY_NAME = "name";
public static final String KEY_PASSWORD = "password";
public static final String KEY_EMAIL = "email";
public DBHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_CONTACTS + "(" + KEY_ID + " integer primary key," + KEY_NAME + " text," + KEY_PASSWORD + " text" + KEY_EMAIL + " text" + ")");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("drop table if exists " + TABLE_CONTACTS);
onCreate(db);
}
}