using System;
using SQLiteSample.TestDataSetTableAdapters;
using System.Data.SQLite;
namespace SQLiteSample
{
class Program
{
static void Main(string[] args)
{
using (var conn = new SQLiteConnection("Data Source=:memory:"))
{
conn.Open();
Console.WriteLine("CREATE TABLE...");
using (var command = conn.CreateCommand())
{
command.CommandText = "CREATE TABLE Person( " +
" ID integer primary key, " +
" Name nvarchar(50), " +
" Age integer)";
var ret = command.ExecuteNonQuery();
Console.WriteLine(ret);
}
Console.WriteLine("INSERT...");
using (var command = conn.CreateCommand())
{
command.CommandText = "INSERT INTO Person(ID, Name, Age) VALUES (@id, @name, @age)";
command.Parameters.Add("id", System.Data.DbType.Int64);
command.Parameters.Add("name", System.Data.DbType.String);
command.Parameters.Add("age", System.Data.DbType.Int64);
for (int i = 0; i < 10; i++)
{
command.Parameters["id"].Value = i;
command.Parameters["name"].Value = "田中 太郎" + i;
command.Parameters["age"].Value = i % 50;
var ret = command.ExecuteNonQuery();
Console.WriteLine(ret);
}
}
Console.WriteLine("SELECT...");
using (var command = conn.CreateCommand())
{
command.CommandText = "SELECT ID, Name, Age FROM Person ORDER BY ID";
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
Console.WriteLine("{0}, {1}, {2}",
reader["ID"], reader["Name"], reader["Age"]);
}
}
}
conn.Close();
}
}
}
}