C # වැඩ්ඩන්ට

weerasinghe

Well-known member
  • Aug 15, 2007
    2,530
    94
    48
    Galgamuwa
    මචංලා මට C # වලට MYSql සම්භන්ද කරලා හදපු පොඩි Project File එකක් හරි, Connect කරන හැටි හරි කියල දෙන්න බැරිද....?

    හදිස්සියි මචංලා....... Please
     

    DragonFox

    Junior member
  • Oct 16, 2009
    369
    9
    18
    Colombo
    Mcn u must download and install the mysql .NET connector first then try the following

    Then Add a referance to MySQL

    then use the following code

    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 MySql.Data;
    using MySql.Data.MySqlClient;
    using MySql.Data.Types;

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

    private void btnConnect_Click(object sender, EventArgs e)
    {
    string MyConString = "SERVER=localhost;" +
    "DATABASE=mydatabase;" +
    "UID=testuser;" +
    "PASSWORD=testpassword;";
    MySqlConnection connection = new MySqlConnection(MyConString);
    MySqlCommand command = connection.CreateCommand();
    connection.Close();
    }

    }
    }


    Project File
     

    Attachments

    • CExample.zip
      21 KB · Views: 190

    weerasinghe

    Well-known member
  • Aug 15, 2007
    2,530
    94
    48
    Galgamuwa

    weerasinghe

    Well-known member
  • Aug 15, 2007
    2,530
    94
    48
    Galgamuwa
    Mcn u must download and install the mysql .NET connector first then try the following

    Then Add a referance to MySQL

    then use the following code

    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 MySql.Data;
    using MySql.Data.MySqlClient;
    using MySql.Data.Types;

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

    private void btnConnect_Click(object sender, EventArgs e)
    {
    string MyConString = "SERVER=localhost;" +
    "DATABASE=mydatabase;" +
    "UID=testuser;" +
    "PASSWORD=testpassword;";
    MySqlConnection connection = new MySqlConnection(MyConString);
    MySqlCommand command = connection.CreateCommand();
    connection.Close();
    }

    }
    }


    Project File


    Thanks Machan... Mama Try Karala balannam..
     

    DragonFox

    Junior member
  • Oct 16, 2009
    369
    9
    18
    Colombo
    mcn i think what u miss is adding a reference to My SQL

    In solution explorer right click on Reference and in the .NET tab select MySql.Data and Click Add that will give you all the required assemblies

    Then try above code