" Just because something doesn't do what you planned it to do doesn't mean it's useless. "  —  Thomas A. Edison (1847 - 1931)
 

Koneksi server database MySQL dengan Connector/NET

more...

Contoh sederhana untuk membuat koneksi database dengan menggunakan MySQL Connector/NET. Connector/NET ini merupakan driver ADO.NET untuk server database MySQL yang 100% dibuat dengan menggunakan bahasa pemrograman C# (fully-managed) untuk .net Framework 2.0 di Microsoft Visual Studio 2005. Informasi lebih lanjut mengenai MySQL Connector/NET untuk Microsoft Visual Studio dan untuk mengunduhnya ada di sini.

Tambahkan namespace:

using MySql.Data.MySqlClient;
using MySql.Data.Types;

Tambahkan kode berikut di source-code aplikasi:

string ConnString = "HOST=localhost;" + "DATABASE=mydb;" + "USERNAME=root;" + "PASSWORD=rootpass;";
MySqlConnection connection = new MySqlConnection( ConnString );
MySqlCommand command = connection.CreateCommand();
MySqlDataReader Reader;
command.CommandText = "SELECT * FROM mytable";
connection.Open();
Reader = command.ExecuteReader();
while ( Reader.Read() )
{
  string thisrow = "";
  for (int i = 0; i < Reader.FieldCount; i++)
    thisrow+=Reader.GetValue(i).ToString() + ",";
  listBox1.Items.Add(thisrow);
}
connection.Close();

Komputer yang menjalankan aplikasi ini tidak memerlukan Connector/NET terinstall didalamnya. Cukup mengikutkan sebuah file MySql.Data.dll.

Sumber:
http://www.geekpedia.com/tutorial228 …

0
Share up your minds and leave a comment
No one has commented yet. Be the first to comment!
Comment Form
XHTML Expert!
You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

* = required fields