반응형
C#에서 DB를 연동하는 가장 간단한 소스이다.. 불필요한것도 있지만..귀찮아서 수정은 안하겠다...ㅎㅎ


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using System.Data.SqlClient;



namespace ConnectDB
{

    public partial class MainWindow : Window
    {
 


        public MainWindow()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
          
            string ConnStr = @"User Id=EX; Password=****; Server=***.**.***.*; Initial Catalog=FStreamDB";
            SqlConnection conn = new SqlConnection(ConnStr);
            SqlCommand command = new SqlCommand();
            command.CommandText = "select musicData from musicTb1";
            command.Connection = conn;
    
            try
            {
                conn.Open();
    
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
            finally
            {
                try
                {
                    if (conn != null)
                    {
                        conn.Close();
                     
                    }
                }
                catch (Exception) { }
            }
        }
    }
}

반응형