概要
cscの作法、調べてみた。
練習問題、やってみた。
練習問題
sqliteで、DataGridViewで表示せよ。
写真
サンプルコード
using System;
using System.Text;
using System.IO;
using System.Drawing;
using System.Windows.Forms;
using System.Data.SQLite;
namespace App
{
class Form1: Form {
public Form1() {
this.Width = 400;
this.Height = 300;
this.Text = "SQLite Test";
DataGridView table = new DataGridView();
table.Dock = DockStyle.Fill;
table.ColumnCount = 4;
table.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
table.Parent = this;
table.Columns[0].HeaderText = "Id";
table.Columns[1].HeaderText = "Name";
table.Columns[2].HeaderText = "Number";
table.Columns[3].HeaderText = "Price";
SQLiteConnection conn = new SQLiteConnection("Data Source=db0.sqlite;");
conn.Open();
SQLiteCommand command = conn.CreateCommand();
command.CommandText = "SELECT * FROM fruit";
SQLiteDataReader reader = command.ExecuteReader();
while (reader.Read())
{
table.Rows.Add(reader.GetInt32(0), reader.GetString(1), reader.GetInt32(2), reader.GetInt32(3));
}
conn.Close();
}
[STAThread]
static void Main() {
Application.Run(new Form1());
}
}
}
以上。