0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

cscの作法 その326

Posted at

概要

cscの作法、調べてみた。
練習問題、やってみた。

練習問題

sqliteで、DataGridViewで表示せよ。

写真

image.png

サンプルコード

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());
		}
	}
}





以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?