using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Odbc;
namespace DataGridView
{
public partial class FormDGV : Form
{
OdbcConnectionStringBuilder con_str = null;
OdbcConnection con = null;
OdbcDataAdapter data_adp = null;
OdbcCommandBuilder con_bld = null;
DataTable dt001 = null;
/*
* コンストラクタ
*/
public FormDGV()
{
InitializeComponent();
con_str = new OdbcConnectionStringBuilder("");
con_str.Dsn = "OracleSpring";
con_str["UID"] = "springjoe2";
con_str["PWD"] = "springjoe2";
con = new OdbcConnection(con_str.ConnectionString);
//接続
try
{
con.Open();
data_adp = new OdbcDataAdapter("SELECT * FROM t1", con);
dt001 = new DataTable();
data_adp.Fill(dt001);
con_bld = new OdbcCommandBuilder(data_adp);
data_adp.UpdateCommand = con_bld.GetUpdateCommand();
data_adp.DeleteCommand = con_bld.GetDeleteCommand();
data_adp.InsertCommand = con_bld.GetInsertCommand();
this.bindingSource1.DataSource = dt001;
this.dataGridView1.DataSource = this.bindingSource1;
this.bindingNavigator1.BindingSource = this.bindingSource1;
this.dataGridView1.Refresh();
}
catch (Exception e)
{
con.Close();
MessageBox.Show(e.Message);
}
}
//フォームの位置を保存
private void FormDGV_FormClosing(object sender, FormClosingEventArgs e)
{
Properties.Settings.Default.Save();
}
//データテーブルの内容を更新
private void button1_Click(object sender, EventArgs e)
{
OdbcTransaction tr = con.BeginTransaction();
try
{
data_adp.Update(dt001);
tr.Commit();
}
catch
{
tr.Rollback();
}
}
}
}
0 件のコメント:
コメントを投稿