Amazing Visual C# Code

heshan123

Member
Jan 12, 2007
3,422
3
0
40
SrI lAnKa
OK guys here is the deal. I some of you are software engineers like me and most of the ppl are into IT in some form. So I believe a knowledge sharing system would be really nice since we have lot of members here. ;)

OK I will start. This is Visual C# Code that I recently came up with to 'remotely' log into a MySQL database and access records. Its not copy right reserved or anything so feel free to make modifications to it if u like. Im fully open source. :D :D

Before u try this code u will have to download the mysql connector/net, it is located at: Click Here

Next add reference to: MySql.Data in your project

Next add "using MySql.Data.MySqlClient;" in your declaration section.

Try the code below.

Code:
private void button1_Click(object sender, System.EventArgs e)
		{
			string conPara = "SERVER=localhost;" +
				"DATABASE=db1;" +
				"UID=testuser;" +
				"PASSWORD=testpassword;";
			MySqlConnection connection = new MySqlConnection(conPara);
			MySqlCommand statement = connection.CreateCommand();
			MySqlDataReader Result;
			statement.CommandText = "select * from customers";
			connection.Open();
			Result = statement.ExecuteReader();
			while (Result.Read())
			{
				string thisrow = "";
				for (int i= 0;i<Reader.FieldCount;i++)
						thisrow+=Result.GetValue(i).ToString() + ",";
				listBox1.Items.Add(thisrow);
			}
			connection.Close();
		}

Ok that should connect you remotely to your MySQL Database and retrieve a record from the table named customers. If there are any questions pls post it here. I will try to answer. ;) ;)