STAY HOME! STAY SaVE

Techies Net
  • Home
  • Software
    • Dotiny
  • Web & App Development
    • Website Builder
    • App Development
  • Request Review
  • Advertise
  • Mobile App
  • Contact Us

How To Connect & Run Queries Of MySQL Database In CSharp (C#) .NET (Visual Studio)

6/2/2015

1 Comment

 
Hey friends, this post is actually for the .net developers who uses Visual Studio for Website development, app development or Windows Forms. In this post we are helping the beginners to know the procedure of connecting an open source MySQL database to your powerful and user friendly IDE - Visual Studio. 
Visual Studio & MySQL
The technique which we are showing is being implemented in Visual Studio 2013 and can be applicable to other versions of visual studio too. This process will help you to use MySQL with your ASP.NET or Windows Forms etc.
Also you should have the knowledge of MySQL localhost and its users privileges. Please see the process below.

How To Connect MySQL To Visual Studio

Pre-Requistics
  • MySQL Database Server
  • Visual Studio
  • MySQL .NET Connector
Steps
  • Download and install all the pre-requistics items mentioned above. Note: Please note down the username & password of MySQL to use it Visual Studio.
  • Open Visual Studio and Add a new project.
Visual Studio - MySQL
  • Now go to solution explorer -> Click on References -> Add Reference
Solution Explorer
  • Now Click on Browse and navigate through this location "C:\Program Files (x86)\MySQL\MySQL Connector Net 5.0.9\Binaries\.NET 2.0" and click on MySql.Data.dll file -> Click Add
MySQL Connector (MySQL.Data.dll)
  • Now Add the following namespace to your newly created project. This namespace helps to use MySQL Data Instances -  (using MySql.Data.MySqlClient)
Mysql.Data.MysqlClient
  • Please use the below code to connect to mysql and enter your queries as required.
MySQL Connection
Copy the Code below
private MySqlConnection Connect()
{
string MyConnectionString = "Server=localhost;Database=networkcop;Uid=networkcopuser;Pwd=network1234";
MySqlConnection connection = new MySqlConnection(MyConnectionString);
return connection;
}
private void Disconnect(MySqlConnection connection)
{
connection.Close();
}
private void button1_Click(object sender, EventArgs e)
{
MySqlConnection con = Connect();
con.Open();
MySqlCommand cmd;
cmd = con.CreateCommand();
cmd.CommandText = "Select * from useractivity";
MySqlDataAdapter adp = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
adp.Fill(ds);
blockurlsdatagrid.Visible = true;
blockurlsdatagrid.DataSource = ds.Tables[0].DefaultView;
}
Output - Mysql Server
  • Enjoy!! and let me know if you have queries.

Author : Shoeb Ahmad Fareed

Shoeb Ahmad Fareed
Designation: Founder & CEO
Bio: A Technology Leninist who believes that success can only be achieved if one has a practical implementation knowledge. He is a Computer Science Engineer, a professional blogger and a debugger.

Share This Post




1 Comment
pandu link
7/2/2015 04:15:15 am

thanks for giving the useful information

Reply



Leave a Reply.

    Get Updates Via Email

    Enter Email Address

    7:00 AM - 9:00 AM IST

    Blog Sponsors


    Category

    All
    Apps
    Camera
    Cars Bikes
    Cloud
    Computers
    Earn Easy Money
    Education
    Entertainment
    Fun
    Games
    How To
    Innovation
    Mobile
    News Internet
    News Internet47f3cea023
    News Internet769585a1ca
    News Of Internet
    News Of Internet
    SmartBand
    Smartwatch
    Software
    Technology

    Archives

    January 2019
    July 2018
    June 2018
    May 2018
    April 2018
    March 2018
    February 2018
    December 2017
    August 2017
    July 2017
    June 2017
    May 2017
    April 2017
    March 2017
    February 2017
    January 2017
    December 2016
    November 2016
    October 2016
    September 2016
    August 2016
    July 2016
    June 2016
    May 2016
    April 2016
    March 2016
    February 2016
    January 2016
    December 2015
    November 2015
    October 2015
    September 2015
    August 2015
    July 2015
    June 2015
    May 2015
    April 2015
    March 2015
    February 2015
    January 2015
    December 2014
    November 2014
    October 2014
    September 2014
    August 2014
    July 2014
    June 2014
    May 2014
    April 2014
    March 2014
    February 2014
    January 2014
    December 2013
    November 2013
    October 2013
    September 2013
    August 2013
    July 2013
    June 2013
    May 2013
    April 2013
    March 2013
    February 2013
    January 2013
    December 2012
    November 2012
    October 2012
    September 2012
    August 2012
    July 2012
    June 2012
    May 2012
    April 2012
    March 2012
    February 2012
    January 2012
    December 2011
    November 2011
    October 2011
    September 2011
    August 2011
    July 2011
    June 2011
    May 2011
    April 2011
    March 2011
    February 2011

Contact Us

Email: support@techiesnet.com

Stay Connected

Download Our Mobile App 

Techies Net Mobile App
Copyright © 2011-2019 Techies Net | Our Logo | Advertise | Careers | Donate Us | All Right Reserved.
All the trademarks are sole property of their respective owners.

Powered By HostChef.In

  • Home
  • Software
    • Dotiny
  • Web & App Development
    • Website Builder
    • App Development
  • Request Review
  • Advertise
  • Mobile App
  • Contact Us