Android 我无法插入数据
我正在制作一个应用程序来插入数据。但当我点击添加按钮,给出所有细节时。应用程序返回我到上一页 这是我创建插入类的方法 下面是我插入数据的编码方式 这是DBHelper类中的addinfo方法 SQLiteDatabase类的insert方法不返回 count,返回插入行的id。你是在检查吗 如果返回结果为1,则这是一个真实的过程,但不是一种 检查insert方法。这意味着你需要检查是否有 返回结果,插入操作已成功执行,但如果 出现问题,应用程序将崩溃 确保创建了要在其中插入数据的表Android 我无法插入数据,android,sqliteopenhelper,Android,Sqliteopenhelper,我正在制作一个应用程序来插入数据。但当我点击添加按钮,给出所有细节时。应用程序返回我到上一页 这是我创建插入类的方法 下面是我插入数据的编码方式 这是DBHelper类中的addinfo方法 SQLiteDatabase类的insert方法不返回 count,返回插入行的id。你是在检查吗 如果返回结果为1,则这是一个真实的过程,但不是一种 检查insert方法。这意味着你需要检查是否有 返回结果,插入操作已成功执行,但如果 出现问题,应用程序将崩溃 确保创建了要在其中插入数据的表 你知道And
你知道Android和Android Studio之间的区别吗?请帮我更正。请放置DBHelper类,或者只是它的addInfo方法。我上传了它。请查收
public class InsertStudent extends AppCompatActivity {
Button instudent;
DBHelper dbHelper;
EditText sName,sDOB,sAddress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_insert_student);
instudent = findViewById(R.id.btninsert);
sName = findViewById(R.id.insertname);
sDOB = findViewById(R.id.insertdob)
;
sAddress = findViewById(R.id.insertaddress);
instudent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String userName = sName.getText().toString();
String dateB = sDOB.getText().toString();
String addr = sAddress.getText().toString();
boolean count = dbHelper.addInfo(userName,dateB,addr );
if(count =true){
Toast.makeText(InsertStudent.this, "Inserted!", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(InsertStudent.this, "Something went wrong!", Toast.LENGTH_SHORT).show();
}
}
});
public boolean addInfo(String stdName, String stdDOB, String stdAddress){
SQLiteDatabase sqLiteDatabase = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(UserProfile.Users.COLUMN_STDNAME, stdName);
contentValues.put(UserProfile.Users.COLUMN_DATEOFBIRTH, stdDOB);
contentValues.put(UserProfile.Users.TABLE_ADDRESS, stdAddress);
long result = sqLiteDatabase.insert(UserProfile.Users.TABLE_NAME, null, contentValues);
if(result==1)
return false;
else
return true;
}
}