C# - How To Make MySQL Database Navigation Buttons In C#
__________________________________________________________________________
In This C# Tutorial We Will See How To Create MySQL Database Records Navigation Buttons In CSharp Programming Language .
In This C# Tutorial We Will See How To Create MySQL Database Records Navigation Buttons In CSharp Programming Language .
Source Code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace Csharp_And_MySQL
{
public partial class Csharp_MySQL_Data_Navigation : Form
{
MySqlConnection connection = new MySqlConnection("datasource=localhost;port=3306;username=root;password=");
MySqlDataAdapter adapter;
DataTable table = new DataTable();
int pos = 0;
public Csharp_MySQL_Data_Navigation()
{
InitializeComponent();
}
private void Csharp_MySQL_Data_Navigation_Load(object sender, EventArgs e)
{
adapter = new MySqlDataAdapter("SELECT * FROM test_db.users",connection);
adapter.Fill(table);
showData(pos);
}
public void showData(int index)
{
textBoxID.Text = table.Rows[index][0].ToString();
textBoxFName.Text = table.Rows[index][1].ToString();
textBoxLName.Text = table.Rows[index][2].ToString();
textBoxAge.Text = table.Rows[index][3].ToString();
}
private void BTN_FIRST_Click(object sender, EventArgs e)
{
pos = 0;
showData(pos);
}
private void BTN_NEXT_Click(object sender, EventArgs e)
{
pos++;
if(pos < table.Rows.Count)
{
showData(pos);
}
else
{
MessageBox.Show("END");
pos = table.Rows.Count - 1;
}
}
private void BTN_PREVIOUS_Click(object sender, EventArgs e)
{
pos--;
if(pos >= 0)
{
showData(pos);
}
else
{
MessageBox.Show("END");
}
}
private void BTN_LAST_Click(object sender, EventArgs e)
{
pos = table.Rows.Count - 1;
showData(pos);
}
}
}
=> OUTPUT:
C# Navigation Buttons |
Download Projects Source Code