winform插入时间类型数据到oracle数据库,winform操作访问Oracle 10g数据库,并自动填充到DataGridView...

使用oracle的ODP.NET是官方推荐,而且相对简单的方法。

官方指导文档:

http://www.oracle.com/technetwork/cn/testcontent/o23odp-084525-zhs.html

9cf5861f702d6a7f0ac07965dc602841.png

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();

}

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值