본문 바로가기
C#

visual studio 2022 와 oracle 연동 해보기

by improve 2024. 2. 7.

using Oracle.ManagedDataAccess.Client;

namespace WinFormsApp2
{
    public partial class Form1 : Form
    {
        String strConnection = "DATA SOURCE =192.168.0.38; User Id=HR; Password=1234;";
        OracleConnection conn;
        OracleCommand cmd;




        public Form1()
        {
            InitializeComponent();

            //            MessageBox.Show(strConnection);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("안녕하세요");
        }

        private void button2_Click(object sender, EventArgs e)
        {

        }
      
    }
}

 

 

버튼을 클릭했을 때 안녕하세요 멘트가 나온다. 

 

 

 

using Oracle.ManagedDataAccess.Client;
using System.Data;

namespace WinFormsApp2
{
    public partial class Form1 : Form
    {
        String ConnectionString = "User Id= hr;Password= 1234; Data Source= 192.168.0.38";
        //String strConnection = "DATA SOURCE =192.168.0.38; User Id=HR; Password=1234;";
        OracleConnection conn;
        OracleCommand cmd;




        public Form1()
        {
            InitializeComponent();

            //            MessageBox.Show(strConnection);
            // 주석처리 단축기 ctrl + k + c
            //mbox tab tab 
        
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //MessageBox.Show("Test"+strConnection);
            conn = new OracleConnection(ConnectionString);
            //cmd = new OracleCommand();
            conn.Open();//data base 열기
            //cmd.Connection = conn;

            DataSet ds = new DataSet();
            String sql = "select * from 학생";
            OracleDataAdapter adapter = new OracleDataAdapter();
            adapter.SelectCommand = new OracleCommand(sql,conn);
            adapter.Fill(ds);

            dataGridView1.DataSource = ds.Tables[0];

            MessageBox.Show(ds.Tables[0].ToString());
  

            
            conn.Close();//data base 닫기
        }

        private void button2_Click(object sender, EventArgs e)
        {

        }
      
    }
}

 

 

버튼 1을 클릭 했을 때 oracle 안에 있는 select * from 학생 는 학생 테이블안에 데이터를 검색해라 라는 말을 

dataGridView1.DataSource = ds.Table[0] 에 나타래라  

 

oracle 데이터베이스와 c#을 연동 해보았다.

 

'C#' 카테고리의 다른 글

라벨 이용하기  (0) 2024.02.16
C# 콘솔  (0) 2024.02.13
c# oracle에서 연동, listbox에 보여주기.  (0) 2024.02.08
계산기  (0) 2024.02.08
C#  (0) 2024.02.02