locked
how to connect with mysql RRS feed

  • Question

  • User2031860760 posted

    i m using vs 2010 professional i want to connect it to mysql database....pls give me a piece of code for that...and tell me where i have to make changes....plssss help me out thnks in advance...

    Thursday, March 24, 2011 2:20 AM

Answers

  • User1805528910 posted

    Download mysql connector for .net and installed it in your system 

    http://dev.mysql.com/downloads/connector/net/

    after installing the connector reference the library and MySql.Data;

    using MySql.Data;
    
    private void button1_Click(object sender, System.EventArgs e)
    		{
    			string MyConString = "SERVER=localhost;" +
    				"DATABASE=mydatabase;" +
    				"UID=testuser;" +
    				"PASSWORD=testpassword;";
    			MySqlConnection connection = new MySqlConnection(MyConString);
    			MySqlCommand command = connection.CreateCommand();
    			MySqlDataReader Reader;
    			command.CommandText = "select * from mycustomers";
    			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();
    		}

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, March 25, 2011 5:24 AM

All replies

  • User1805528910 posted

    Download mysql connector for .net and installed it in your system 

    http://dev.mysql.com/downloads/connector/net/

    after installing the connector reference the library and MySql.Data;

    using MySql.Data;
    
    private void button1_Click(object sender, System.EventArgs e)
    		{
    			string MyConString = "SERVER=localhost;" +
    				"DATABASE=mydatabase;" +
    				"UID=testuser;" +
    				"PASSWORD=testpassword;";
    			MySqlConnection connection = new MySqlConnection(MyConString);
    			MySqlCommand command = connection.CreateCommand();
    			MySqlDataReader Reader;
    			command.CommandText = "select * from mycustomers";
    			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();
    		}

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, March 25, 2011 5:24 AM
  • User2031860760 posted

    i have downloaded connector for vs 2010...and install it....now plsss tell me what all changes i have to do in web.config and machine.config........or tell is there any other place or file in which i have to change....plsss tell me the complete process i m stuck....thnx in advance....

    Friday, March 25, 2011 5:39 AM
  • User1805528910 posted

    have you tested the example which i have  posted in my last post?

    If not than only you need to add reference of MySql.Data in your project nothing else and you will able to used it 

    are you getting any error in your in my code which i have posted?

    Friday, March 25, 2011 6:24 AM