当前位置:编程学习 > C#/ASP.NET >>

关于c#连接oracle 请大家帮忙啊,谢谢啊!

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Data.OracleClient;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“dataSet1.TABSALORDER”中。您可以根据需要移动或移除它。
            this.tABSALORDERTableAdapter.Fill(this.dataSet1.TABSALORDER);

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string constring = "data source=hq100;user=hq2005;password=hq2005;";
            OracleConnection conn = new OracleConnection(constring);
            try
            {
                conn.Open();//打开指定的连接  
                OracleCommand com = conn.CreateCommand();
                com.CommandText = "select * from tabsalorder";
                OracleDataReader odr = com.ExecuteReader();
                while (odr.Read())
                {
                    this.lbl.Text = odr.GetOracleString(0).ToString();//
                }
                odr.Close();//
            }
            catch
            {
                MessageBox.Show("erro");//如果发生异常,则提示出错  
            }
            finally
            {
                conn.Close();//关闭打开的连接 
            }
        }
    }
}
//  while (odr.Read())
                {
                    this.lbl.Text = odr.GetOracleString(0).ToString();//请问这句话什么意思啊?
                }
                odr.Close();//

//小弟学c#与oracle 连接,但是看不懂如何把数据传递DataGridView,显示出来。请各位大家帮忙,小弟该如何尽快的学习C# 连接oracle,或者是专有的c#连接oracle的资料,非常感激。
--------------------编程问答-------------------- c#连接oracle跟链接SQL是一样的。
通过SQL语句返回DataTable,然后在跟DataGridView绑定即可。 --------------------编程问答-------------------- http://www.360doc.com/content/11/0511/16/3705007_115979476.shtml

http://wenku.baidu.com/view/5124c3d233d4b14e852468a9.html --------------------编程问答--------------------

private DataSet TestCon()
        {
            try
            {
                OracleConnection con = new OracleConnection("server=.;database=northwind;uid=sa;pwd=123456");
                OracleCommand cmd = con.CreateCommand();
                cmd.CommandText = "select * from tablename";
                OracleDataAdapter adp = new OracleDataAdapter(cmd);
                DataSet ds = new DataSet();
                adp.Fill(ds);

                return ds;
            }
            catch
            {
                return null;
            }
        }
        private void BindGridView(DataSet ds,DataGridView dgv)
        {
            dgv.DataSource = null;
            if (ds != null && ds.Tables.Count > 0)
            {
                dgv.DataSource = ds.Tables[0];
            }
        }
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,