banner



How To Register Access Code In Blackboard Mcgraw Connect

Learn how to ready a local connection between winforms and mySQL.

XAMPP is a free and open source cantankerous-platform web server solution stack packet developed by Apache Friends, consisting mainly of the Apache HTTP Server, MariaDB database, and interpreters for scripts written in the PHP and Perl programming languages.

If yous utilise xampp, you probably know how easy is to create and maintain databases with the integrated module of phpmyadmin. Yous may notice easily to piece of work with PHP, but, if you have .NET knowledge you can start working with information technology likewise.

MySQL offers a connector a like shooting fish in a barrel connector that will allow you lot to execute queries to phpmyadmin from your winform.

In this article we'll larn how to access a database created in phpmyadmin using winforms in C# easily.

Requirements

  • Visual Studio (any version).
  • MySQL .NET Connector Extension.
  • XAMPP Distribution (we'll presume that you know how to use mysql and xampp).

Implementation

This task is more easy than you recall, to achieve a succesfully implementation follow these steps :

  • Add together the reference to the MySQL connector to your winform projection.
  • Create your database (ignore if y'all already have any) in MySQL with PHPMyAdmin.
  • Beginning to execute queries.

Add the reference to the MySQL connector to the project

To get started, you need obligatory the .Internet MySQL extension installed in your system as nosotros need to add together the reference in our project afterwards. You lot tin cull one of the latest version in the official website of MySQL.

Install on your system mysql connector extension

You can cull wether a complete installation or typical.

Installation

Afterwards the installation, we are going to proceed to create an empty Winforms project in Visual Studio as you usually practise.

At present nosotros need to add the reference to the mysql connector in our project. Locate the solution explorer in the right pinnacle corner of Visual Studio when your project is open, use right click on References and so select Add together Reference from the context carte.

References .net C#

In the shown menu, navigate to Extensions and select the checkbox from the list the MySql.Data (MySql.Information.dll) and then click on OK.

MySQL data .net C# reference

At present we'll be able to connect to execute queries to MySQL with C#.

Creating a test database in phpmyadmin (localhost)

As mentioned earlier, we assume that you already accept Xampp installed on your system and you know how to apply it.

First, practice not forget to enable the apache and mysql services in the xampp console (which is recommended in Administrator mode).

Xampp menu

Now navigate in your browser to http://localhost/phpmyadmin and go to the databases expanse.

Create a database (in this example our database will be test) and create a table named user.

PHPMyAdmin mySql table

Note

Remember to enable the autoincrementable option to the id field, otherwise y'all'll need to add an id everytime you lot insert a row.

Now that our database "test" contains at least one tabular array "user", nosotros can showtime executing queries.

Using C# to connect and execute queries

At present comes the fun part ! we'll write some code to interact with the MySQL database. Primary, don't forget to add the using statement of the reference in your grade :

          using MySql.Data.MySqlClient;        

You tin can understand how works the connectedness and how to execute a query with the post-obit snippet :

          // Change the username, password and database according to your needs // You can ignore the database option if you want to access all of them. // 127.0.0.one stands for localhost and the default port to connect. string connectionString = "datasource=127.0.0.one;port=3306;username=root;password=;database=test;"; // Your query, string query = "SELECT * FROM user";  // Set up the connection MySqlConnection databaseConnection = new MySqlConnection(connectionString); MySqlCommand commandDatabase = new MySqlCommand(query, databaseConnection); commandDatabase.CommandTimeout = lx; MySqlDataReader reader;   // Let's exercise information technology ! effort {     // Open the database     databaseConnection.Open();      // Execute the query     reader = commandDatabase.ExecuteReader();      // All succesfully executed, now do something      // Important :      // If your query returns effect, use the following processor :          if (reader.HasRows)     {         while (reader.Read())         {             // As our database, the array will contain : ID 0, FIRST_NAME i,LAST_NAME 2, Accost 3             // Exercise something with every received database ROW             string[] row = { reader.GetString(0), reader.GetString(ane), reader.GetString(two), reader.GetString(3) };         }     }     else     {         Console.WriteLine("No rows found.");     }      // Finally close the connection     databaseConnection.Close(); } grab (Exception ex) {     // Show any error message.     MessageBox.Prove(ex.Message); }        

And that's it ! Basically, y'all merely need to change the query and start testing. You lot tin can read more well-nigh the connexion string and all the available properties here.

Basic examples of queries

In these examples nosotros are going to execute the most basic tasks to execute (CRUD):

Form insertion

Note that we'll utilize a uncomplicated listView component (with 4 columns : id,start name, terminal name and address), three textBox and ii Buttons.

Create

In the following snippet, we'll create a register in the examination database :

          private void SaveUser() {     cord connectionString = "datasource=127.0.0.1;port=3306;username=root;countersign=;database=test;";     string query = "INSERT INTO user(`id`, `first_name`, `last_name`, `address`) VALUES (NULL, '"+textBox1.Text+ "', '" + textBox2.Text + "', '" + textBox3.Text + "')";     // Which could exist translated manually to :     // INSERT INTO user(`id`, `first_name`, `last_name`, `address`) VALUES (NULL, 'Bruce', 'Wayne', 'Wayne Estate')          MySqlConnection databaseConnection = new MySqlConnection(connectionString);     MySqlCommand commandDatabase = new MySqlCommand(query, databaseConnection);     commandDatabase.CommandTimeout = 60;          try     {         databaseConnection.Open();         MySqlDataReader myReader = commandDatabase.ExecuteReader();                  MessageBox.Prove("User succesfully registered");             databaseConnection.Shut();     }     catch (Exception ex)     {         // Show any error message.         MessageBox.Prove(ex.Message);     } }        

Show

In the following snippet we'll listing all the users in the examination database in a listview (if available or evidence in the console) :

          private void listUsers() {     cord connectionString = "datasource=127.0.0.one;port=3306;username=root;password=;database=exam;";     // Select all     string query = "SELECT * FROM user";      MySqlConnection databaseConnection = new MySqlConnection(connectionString);     MySqlCommand commandDatabase = new MySqlCommand(query, databaseConnection);     commandDatabase.CommandTimeout = 60;     MySqlDataReader reader;      try     {         databaseConnection.Open();         reader = commandDatabase.ExecuteReader();         // Success, now list           // If there are available rows         if (reader.HasRows)         {             while (reader.Read())             {                                      ID                              Get-go name                  Terminal Name                    Address                 Console.WriteLine(reader.GetString(0) + " - " + reader.GetString(1) + " - " + reader.GetString(2) + " - " + reader.GetString(3));                 // Instance to save in the listView1 :                 //string[] row = { reader.GetString(0), reader.GetString(1), reader.GetString(ii), reader.GetString(3) };                 //var listViewItem = new ListViewItem(row);                 //listView1.Items.Add together(listViewItem);             }         }         else         {             Console.WriteLine("No rows found.");         }          databaseConnection.Close();     }     catch (Exception ex)     {         MessageBox.Show(ex.Message);     } }        

Update

Update the fields of a row with id :

          private void updateUser() {     string connectionString = "datasource=127.0.0.ane;port=3306;username=root;password=;database=test;";     // Update the backdrop of the row with ID 1     string query = "UPDATE `user` SET `first_name`='Willy',`last_name`='Wonka',`address`='Chocolate manufactory' WHERE id = one";      MySqlConnection databaseConnection = new MySqlConnection(connectionString);     MySqlCommand commandDatabase = new MySqlCommand(query, databaseConnection);     commandDatabase.CommandTimeout = sixty;     MySqlDataReader reader;      try     {         databaseConnection.Open();         reader = commandDatabase.ExecuteReader();                  // Succesfully updated          databaseConnection.Shut();     }     catch (Exception ex)     {         // Ops, maybe the id doesn't exists ?         MessageBox.Evidence(ex.Message);     } }        

Delete

Delete a row with ID (x) :

          private void deleteUser() {     string connectionString = "datasource=127.0.0.1;port=3306;username=root;countersign=;database=test;";     // Delete the particular with ID 1     string query = "DELETE FROM `user` WHERE id = ane";      MySqlConnection databaseConnection = new MySqlConnection(connectionString);     MySqlCommand commandDatabase = new MySqlCommand(query, databaseConnection);     commandDatabase.CommandTimeout = sixty;     MySqlDataReader reader;      try     {         databaseConnection.Open up();         reader = commandDatabase.ExecuteReader();                  // Succesfully deleted          databaseConnection.Shut();     }     catch (Exception ex)     {         // Ops, maybe the id doesn't exists ?         MessageBox.Evidence(ex.Bulletin);     } }        

Take fun !

Source: https://ourcodeworld.com/articles/read/218/how-to-connect-to-mysql-with-c-sharp-winforms-and-xampp

Posted by: shawstookins.blogspot.com

0 Response to "How To Register Access Code In Blackboard Mcgraw Connect"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel