1,导入第三方头文件

#import "FMDB.h"

//定义全局变量

@implementation InputInformationViewController

{

UITextField *_accountField;//帐号输入框

UITextField *_passwordsField;//密码输入框

FMDatabase *db;//数据库

}

//获取数据库

NSString *doc = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask , YES) lastObject];

NSLog(@"%@",doc);

NSString *fileName = [doc stringByAppendingPathComponent:@"information.sqlite"];

//获取数据库

db = [FMDatabase databaseWithPath:fileName];

if ([db open]) {

//创表

BOOL result = [db executeUpdate:@"CREATE TABLE IF NOT EXISTS M_Information (id integer PRIMARY KEY AUTOINCREMENT, account NOT NULL,passwords text NOT NULL);"];

if (result) {

NSLog(@"创表成功");

}else{

NSLog(@"创表失败");

}

}

//获取数据

NSString *account = _accountField.text;

NSString *passwords = _passwordsField.text;

if([db executeUpdate:@"INSERT INTO M_Information(account,passwords) VALUES(?,?);",account,passwords]){

NSLog(@"111");

};

//[db executeQueryWithFormat:@"INSERT INTO M_Information(account,passwords)VALUES(%@,%@);",account,passwords];

[self query];//执行查询语句

//查询语句函数

   ViewController *VC = [[ViewController alloc]init];

VC.dataArray = [[NSMutableArray alloc]init];

//执行查询语句

FMResultSet *resultSet = [db executeQuery:@"SELECT * FROM M_Information"];

//遍历结果集

while ([resultSet next]) {

//传递数据库中的数据

InformationModel *model = [[InformationModel alloc]init];

model.myAccount = [resultSet stringForColumn:@"account"];

model.myPasswords = [resultSet stringForColumn:@"passwords"];

[VC.dataArray addObject:model];

}

最新文章

  1. 【C#】ConcurrentBag<T> 方法
  2. 数据流 in redux
  3. 访问ControlTemplate内部的元素
  4. android系统360浏览器使用append动态添加元素出现黑色错乱背景
  5. 微软分布式缓存 appfabric
  6. 当在浏览器地址栏里输入URL后会发生什么事情
  7. Java 8 新特性1-函数式接口
  8. JAVA入门[7]-Mybatis generator(MBG)自动生成mybatis代码
  9. HibernateTemplate#setMaxResults()的坑
  10. java I/O框架 (三)基本流
  11. Kali Linux入坑之基本配置(2018.1)
  12. 用python爬取杭电oj的数据
  13. 微信小程序手机预览请求不到数据(最后一条不明所以)
  14. Linux 系统安全设置
  15. Flutter - AAPT: error: resource android:attr/dialogCornerRadius not found.
  16. springMVC学习三 注解开发环境搭建
  17. Haskell语言学习笔记(42)Bifunctor
  18. Retrofit源码解析(下)
  19. php 返回上一页并刷新
  20. MySQL Innodb 神秘消失

热门文章

  1. Python学习---除法
  2. Python之路 day3 全局变量、局部变量
  3. neatbean 8+版本 配置
  4. Map的五种遍历方法
  5. 收集C#常用类:自己写的一个DBHelper类
  6. javascript学习之Function 类型
  7. angularjs的一些坑关于 $sec
  8. AutoCAD安装失败
  9. MVC5+EF6 入门完整教程十
  10. ASP.net Core部署说明(Ubuntu) [转]