winform插入时间类型数据到oracle数据库,winform操作访问Oracle 10g数据库,并自动填充到DataGridView...
使用oracle的ODP.NET是官方推薦,而且相對簡單的方法。
官方指導文檔:
http://www.oracle.com/technetwork/cn/testcontent/o23odp-084525-zhs.html
app.config
Form1.aspx.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Collections;
using Oracle.DataAccess.Client;
namespace JiaJiayue
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string connstring = ConfigurationSettings.AppSettings["ORACLE"];
//private DataGridView dataGridView1 = new DataGridView();
private BindingSource bindingSource1 = new BindingSource();
private OracleDataAdapter dataAdapter = new OracleDataAdapter();
//string connstring = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.133)(PORT=1521))(CONNECT_DATA=(SID=yy)));User Id=system;Password=orcl;";
private void btnSearch_Click(object sender, EventArgs e)
{
dataGridView1.DataSource = bindingSource1;
if (txtName.Text == "")
{
GetData("select tbm_psndoc.timecardid,psnname,deptname from tbm_psndoc left join bd_psndoc on tbm_psndoc.pk_psndoc=bd_psndoc.pk_psndoc left join bd_deptdoc on bd_psndoc.pk_deptdoc=bd_deptdoc.pk_deptdoc");
}
else
{
GetData("select tbm_psndoc.timecardid,psnname,deptname from tbm_psndoc left join bd_psndoc on tbm_psndoc.pk_psndoc=bd_psndoc.pk_psndoc left join bd_deptdoc on bd_psndoc.pk_deptdoc=bd_deptdoc.pk_deptdoc where psnname='" + txtName.Text + "'");
}
}
private void GetData(string selectCommand)
{
try
{
// Create a new data adapter based on the specified query.
dataAdapter = new OracleDataAdapter(selectCommand, connstring);
// Create a command builder to generate SQL update, insert, and
// delete commands based on selectCommand. These are used to
// update the database.
OracleCommand commandBuilder = new OracleCommand();
// Populate a new data table and bind it to the BindingSource.
DataTable table = new DataTable();
table.Locale = System.Globalization.CultureInfo.InvariantCulture;
dataAdapter.Fill(table);
bindingSource1.DataSource = table;
// Resize the DataGridView columns to fit the newly loaded content.
dataGridView1.AutoResizeColumns(
DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
}
catch
{
}
}
private void 更新ToolStripMenuItem1_Click(object sender, EventArgs e)
{
Form2 formone = new Form2();
formone.Show();
}
}
}
總結
以上是生活随笔為你收集整理的winform插入时间类型数据到oracle数据库,winform操作访问Oracle 10g数据库,并自动填充到DataGridView...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: oracle 删除空间不足,oracle
- 下一篇: oracle内外链接混合用,混合在一起通