Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Data.OleDb;
- namespace TestDatabaseApp_5
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private DataTable dt = new DataTable();
- private int cnt = 0;
- private DataSet ds = new DataSet();
- private void Btn1_Click(object sender, EventArgs e)
- {
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- this.ActiveControl = this.txtBox1;
- }
- private void txtBox1_TextChanged(object sender, EventArgs e)
- {
- OleDbConnection conn = new OleDbConnection();
- OleDbCommand comm = new OleDbCommand();
- long LJAN;
- LJAN = Convert.ToInt64(txtBox1.Text);
- LJAN = long.Parse(txtBox1.Text);
- int len;
- len = (LJAN == 0) ? 1 : ((int)Math.Log10(LJAN) + 1);
- conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\user2\Documents\Documents\TestData_2.accdb"; // MDB名など
- dataGridView1.AutoGenerateColumns = false;
- DataGridViewColumn column = new DataGridViewTextBoxColumn();
- // 接続します。
- conn.Open();
- // SELECT文を設定します。
- comm.CommandText = "SELECT * FROM test_data";
- comm.Connection = conn;
- OleDbDataAdapter oda = new OleDbDataAdapter();
- oda.SelectCommand = comm;
- // 結果を表示します。
- //DataSet ds = new DataSet();
- oda.Fill(ds, "data");
- DataView dv = new DataView();
- if (len == 13)
- {
- dv = new DataView(ds.Tables[0], "id=" + LJAN, null, DataViewRowState.CurrentRows);
- cnt += 1;
- dataGridView1.DataSource = dv;
- dataGridView1.Columns[3].DataPropertyName = "price";
- dataGridView1.Columns[1].DataPropertyName = "name";
- // 接続を解除します。
- DataRowView dtrv = dv.AddNew();
- conn.Close();
- //dataGridView1.DataSource = null;
- }
- if (len >= 13)
- {
- txtBox1.SelectAll();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement