ContentValues用来存储数据,key只能是String类型,values只能存储基本类型的数据,像string,int之类的,不能存储对象这种东西。ContentValues 常用在数据库中的操作。
ContentValues cv = new ContentValues();
cv.put("CATInId", InID);//列的名称,列的值
SimpleDateFormat format = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
String date = format.format(new Date());
cv.put("Date", date); //获取当前时间
mDatabase.insert("MyTab", null, cv);//插入到MyTab的表中
本文介绍了ContentValues类的基本用法,包括如何使用它来存储数据,其中数据的键必须为String类型,值则可以是基本类型如字符串或整数等。此外,还详细展示了如何创建ContentValues实例,并通过示例说明了如何将当前时间格式化后存入ContentValues,最后将其插入到指定的数据库表中。
1万+

被折叠的 条评论
为什么被折叠?



