国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 海口市| 桂阳县| 嘉黎县| 莲花县| 集贤县| 海兴县| 聂拉木县| 蒲城县| 津市市| 张家口市| 武宁县| 松溪县| 光山县| 桂林市| 德庆县| 青海省| 盐源县| 明光市| 神木县| 安阳县| 平遥县| 瑞昌市| 禹州市| 钟祥市| 河北区| 定州市| 孝义市| 黔西| 祁门县| 通化市| 朝阳县| 宣城市| 邓州市| 东光县| 利川市| 白银市| 涡阳县| 连江县| 睢宁县| 修水县| 朝阳区|