国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

c#ado連接數(shù)據(jù)庫 六步曲

2019-11-14 16:33:08
字體:
供稿:網(wǎng)友

建立連接分為六步:
1.定義連接字符串,Oracle 的連接字符串為:

                        192.168.1.130:1521/mydata;Persist Security Info=True;User ID=em_test;PassWord=test123;Unicode=True";

2.根據(jù)連接字符串成連接
3.打開連接
4.實例命令對象
5.操作
6.關(guān)閉連接

看一個例子: 

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.OracleClient;

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

        private void button1_Click(object sender, EventArgs e)
        {
            OracleConnection connection = null;
            int num = 0;
            string message = "";
            String sql = "select count(*) from ex_user";
            try
            {
                string connString = "Data Source=mydata;Persist Security Info=True;User ID=test;Password=huikk123;Unicode=True";

                // 創(chuàng)建connection對象
                connection = new OracleConnection(connString);

                // 打開連接
                connection.Open();
                OracleCommand command = new OracleCommand(sql, connection);
                num = int.Parse(command.ExecuteScalar().ToString());
                message = string.Format("共有{0}條用戶信息!", num);
                MessageBox.Show(message);
            }
            catch (Exception ex)
            {

                MessageBox.Show("出現(xiàn)異常"+ex.Message);
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }
        }
    }
}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 道真| 枝江市| 马鞍山市| 瑞丽市| 汉川市| 云林县| 庆元县| 平果县| 永城市| 聂拉木县| 鄄城县| 日喀则市| 行唐县| 富裕县| 麻城市| 宁强县| 麻栗坡县| 潜江市| 岳池县| 曲水县| 富民县| 宿迁市| 乌兰察布市| 澄迈县| 育儿| 比如县| 镇沅| 牙克石市| 陵川县| 五寨县| 沭阳县| 隆化县| 宁蒗| 黄龙县| 英山县| 乌拉特中旗| 夏河县| 屏南县| 青田县| 丹棱县| 花垣县|