oracle 测试代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using System.Runtime.InteropServices;
using Oracle.DataAccess;
namespace testjpcn
{
public partial class Form1 : Form
{
[DllImport("kernel32.dll", SetLastError = true)]
static extern int GetThreadLocale();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Oracle.DataAccess.Client.OracleConnection ocn = new Oracle.DataAccess.Client.OracleConnection();
ocn.ConnectionString = "User Id=System;Password =oracle;Data Source=ujpcn";
ocn.Open();
Oracle.DataAccess.Client.OracleCommand ocmd = new Oracle.DataAccess.Client.OracleCommand();
ocmd.CommandText = "INSERT INTO TEST (ID,MEMO) VALUES('" + System.DateTime.Now.ToLongTimeString() + "','" + textBox1.Text+"')";
ocmd.Connection = ocn;
ocmd.ExecuteNonQuery();
Oracle.DataAccess.Client.OracleDataAdapter odp = new Oracle.DataAccess.Client.OracleDataAdapter();
DataSet ds = new DataSet();
Oracle.DataAccess.Client.OracleCommand ocmd1 = new Oracle.DataAccess.Client.OracleCommand();
ocmd1.CommandText = "select * from test";
ocmd1.Connection = ocn;
odp.SelectCommand = ocmd1;
odp.Fill(ds);
this.dataGridView1.DataSource = ds.Tables[0];
}
private void Form1_Load(object sender, EventArgs e)
{
CultureInfo cInfo = CultureInfo.GetCultureInfo(GetThreadLocale());
this.label2.Text = cInfo.CompareInfo.Name.ToString();
Oracle.DataAccess.Client.OracleConnection ocn = new Oracle.DataAccess.Client.OracleConnection();
ocn.ConnectionString = "User Id=System;Password =oracle;Data Source=ujpcn";
ocn.Open();
Oracle.DataAccess.Client.OracleCommand ocmd= new Oracle.DataAccess.Client.OracleCommand();
ocmd.CommandText = "select * from test";
ocmd.Connection = ocn;
Oracle.DataAccess.Client.OracleDataAdapter odp = new Oracle.DataAccess.Client.OracleDataAdapter();
DataSet ds = new DataSet();
odp.SelectCommand = ocmd;
odp.Fill(ds);
this.dataGridView1.DataSource = ds.Tables[0];
}
}
}