C#操作sqlite数据库表中的boolean项
2个回答
展开全部
C#下SQLite操作驱动dll下载:System.Data.SQLite
C#使用SQLite步骤:
(1)新建一个project
(2)添加SQLite操作驱动dll引用
(3)使用API操作SQLite DataBase
using System;
using System.Data.SQLite;
namespace SQLiteSamples
{
class Program
{
//数据库连接
SQLiteConnection m_dbConnection;
static void Main(string[] args)
{
Program p = new Program();
}
public Program()
{
createNewDatabase();
connectToDatabase();
createTable();
fillTable();
printHighscores();
}
//创建一个空的数据库
void createNewDatabase()
{
SQLiteConnection.CreateFile("MyDatabase.sqlite");
}
//创建一个连接到指定数据库
void connectToDatabase()
{
m_dbConnection = new SQLiteConnection("Data Source=MyDatabase.sqlite;Version=3;");
m_dbConnection.Open();
}
//在指定数据库中创建一个table
void createTable()
{
string sql = "create table highscores (name varchar(20), score int)";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
}
//插入一些数据
void fillTable()
{
string sql = "insert into highscores (name, score) values ('Me', 3000)";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
sql = "insert into highscores (name, score) values ('Myself', 6000)";
command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
sql = "insert into highscores (name, score) values ('And I', 9001)";
command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
}
//使用sql查询语句,并显示结果
void printHighscores()
{
string sql = "select * from highscores order by score desc";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
SQLiteDataReader reader = command.ExecuteReader();
while (reader.Read())
Console.WriteLine("Name: " + reader["name"] + "\tScore: " + reader["score"]);
Console.ReadLine();
}
}
}
C#使用SQLite步骤:
(1)新建一个project
(2)添加SQLite操作驱动dll引用
(3)使用API操作SQLite DataBase
using System;
using System.Data.SQLite;
namespace SQLiteSamples
{
class Program
{
//数据库连接
SQLiteConnection m_dbConnection;
static void Main(string[] args)
{
Program p = new Program();
}
public Program()
{
createNewDatabase();
connectToDatabase();
createTable();
fillTable();
printHighscores();
}
//创建一个空的数据库
void createNewDatabase()
{
SQLiteConnection.CreateFile("MyDatabase.sqlite");
}
//创建一个连接到指定数据库
void connectToDatabase()
{
m_dbConnection = new SQLiteConnection("Data Source=MyDatabase.sqlite;Version=3;");
m_dbConnection.Open();
}
//在指定数据库中创建一个table
void createTable()
{
string sql = "create table highscores (name varchar(20), score int)";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
}
//插入一些数据
void fillTable()
{
string sql = "insert into highscores (name, score) values ('Me', 3000)";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
sql = "insert into highscores (name, score) values ('Myself', 6000)";
command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
sql = "insert into highscores (name, score) values ('And I', 9001)";
command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
}
//使用sql查询语句,并显示结果
void printHighscores()
{
string sql = "select * from highscores order by score desc";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
SQLiteDataReader reader = command.ExecuteReader();
while (reader.Read())
Console.WriteLine("Name: " + reader["name"] + "\tScore: " + reader["score"]);
Console.ReadLine();
}
}
}
推荐于2017-12-15
展开全部
在xcode的datamodeld 文件中定义了一个 数据表单。其中有个字段是Boolean的类型
生成的对应的 class是 NSNumber 类型
在程序中要通过这种方式进行赋值
[cpp] view plaincopy
questionnaireItem.uploaded= [NSNumber numberWithBool:NO];
生成的对应的 class是 NSNumber 类型
在程序中要通过这种方式进行赋值
[cpp] view plaincopy
questionnaireItem.uploaded= [NSNumber numberWithBool:NO];
追问
不是手机...... 是winform操作sqlite
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询