Membuat Koneksi ke Database menggunakan C#

Membuat Koneksi ke Database menggunakan C#

Create: | Sabtu, 06 Mei 2017 | 21:33:12 WITA | dibaca: 469

Untuk menggunakan database yang telah kita buat, hal pertama yang perlu kita lakukan adalah membuat koneksi ke database. Nah, disini salah satu cara mengkoneksikan database dengan bahasa pemprograman C#. Berikut listing programnya : 

 

 

using System.Windows.Forms;

using MySql.Data.MySqlClient;

namespace membuat_koneksi_database

{

    class Koneksi

    {

        //Mendeklarasikan Variable untuk koneksi ke database

        public static string host = "localhost";

        public static string username = "root";

        public static string database = "mhs";

        public static string password = "";

 

        public static string connect = "server=" + host + ";username=" + username + ";database=" + database + ";password=" + password;

        public static MySqlConnection konek = new MySqlConnection(connect);

       

        public static void konn()

        {

            try

            {

                konek.Open();

                MessageBox.Show("KONEKSI OK");

            }

            catch

            {

                konek.Close();

                MessageBox.Show("KONEKSI TIDAK OK");

            }

        }

    }

 

Untuk membuat tampilan Form sendiri, berikut caranya : 

using System;

using System.Windows.Forms;

 

namespace membuat_koneksi_database

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private void Cek_Click(object sender, EventArgs e)

        {

            //Pemanggilan Fungsi konn

            Koneksi.konn();

        }

    }

 

 

Nah, ini tampilannya setelah koneksi berhasil dijalankan



13 KOMENTAR

json formatter | 15 Mei 2017 || 11:00:58
" Untuk menggunakan database yang telah kita buat "
Reviews of essay writing service | 15 Mei 2017 || 13:12:02
" I valued and really like your submit because all the points inside this proportion turned into very clean and understandable. Thanks for sharing the data, maintain up the good points.... I simply enjoyed exploring your publish. Right useful resource. "
slope | 31 Mei 2017 || 08:40:03
" Thanks for publishing such useful information. "
fake yeezys | 29 Juli 2017 || 10:42:01
" I still liked this article, good, good content, and unique design.Thank you for sharing the article. "
instagram video downloader | 11 Agustus 2017 || 16:44:47
" Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing. "
happy wheels | 11 Agustus 2017 || 16:45:14
" Much thanks to you for your fascinating infomation "
five nights at freddy’s | 11 Agustus 2017 || 16:46:02
" Very helpful advice in this particular post! It’s the little changes that make the largest changes. Thanks for sharing! "
happy wheels now | 25 Agustus 2017 || 09:54:50
" Great post. I found your website perfect for my needs. Very useful info specifically the last part. Thank you for sharing with us, and we sincerely hope you will continue to update or post other articles "
color switch | 30 Agustus 2017 || 16:36:16
" I love the new site!! I know how much time, thought, and hard work it takes to bring a new site to fruition. You've done it, and beautifully! I'm raising my glass of tea to you in celebration of this enormous achievement!!! Hopefully, one day I'll have the pleasure to clink glasses with you personally! "
produk mobil mitsubishi | 11 September 2017 || 15:38:22
" data basenya pakenya xampp atau wamp "
Aalap | 12 September 2017 || 10:17:27
" liked this article, good, good content, and unique design.Thank you for sharing the article. "
Paket Kredit Mobil Honda Samarinda Terbaru | 13 September 2017 || 09:54:13
" i like this "
sewa mobil semarang | 14 September 2017 || 09:54:49
" good content "



ISI KOMENTAR

NAMA

WEBSITE

KOMENTAR


Captcha Sepakbola
Apakah anda manusia?Lebih baik lagi kalau anda menyukai sepak bola
Sebutkan pemain sepak bola disamping:

Captcha Sepakbola by codingwear






  • PELATIHAN KAMPUS
  • Pelatihan Komputer (DIGITAL SCHOOL)
  • Study Tour GoTv
  • Penerimaan Calon Anggota Angkatan XX "Explore Experience With Us"
  • IT FUN