0
1

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の作法 その332

Posted at

概要

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

練習問題

sqliteでdatagridviewでseachボタンを実装せよ。

写真

image.png

サンプルコード

using System;
using System.Text;
using System.IO;
using System.Drawing;
using System.Windows.Forms;
using System.Data;
using System.Data.Common;
using System.Transactions;
using System.Data.SQLite;

class form1: Form {
	private SQLiteDataAdapter dataAdapter = new SQLiteDataAdapter();
	private DataGridView gd0 = new DataGridView();
	private Button sButton = new Button();
	private TextBox bo1 = new TextBox();
	form1() {
		Text = "DataGridView";
		ClientSize = new Size(600, 400);
		bo1.Location = new Point(150, 20);
		bo1.Text = "amazon";
		sButton.Location = new Point(300, 20);
		sButton.Text = "search";
		gd0.Location = new Point(50, 60);
		gd0.Size = new Size(500, 300);
		sButton.Click += new EventHandler(SButton_Click);
		Controls.AddRange(new Control[] {
			bo1,
			sButton,
			gd0
		});
		SQLiteConnection conn = new SQLiteConnection("Data Source=db0.sqlite;");
		conn.Open();
		SQLiteCommand command = conn.CreateCommand();
		command.CommandText = "SELECT * FROM cdata";
		dataAdapter = new SQLiteDataAdapter(command);
		DataTable dt = new DataTable();
		dataAdapter.Fill(dt);
		gd0.DataSource = dt;
		conn.Close();
	}
	private void SButton_Click(object sender, EventArgs e) {
		DataTable dt = (DataTable) gd0.DataSource;
		DataView dv = dt.DefaultView;
		dv.RowFilter = string.Format("[{0}] LIKE '%{1}%'", "biko", bo1.Text);
	}
	[STAThread]
	public static void Main() {
		Application.Run(new form1());
	}
}





以上。

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?