The source code is available here!
/////////// DBGenral class function for (Display data on gidview)///////
using MetroFramework.Controls;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace BCSBatch9E.Database
{
class DBGeneral:DBConnection
{
public SqlCommand CMD;
//Displaying Data On GridView...
public void DisplayData(string query, DataGridView grd)
{
OpenConnection();
CMD.CommandText = query;
SqlDataAdapter ad = new SqlDataAdapter(CMD);
DataTable dt = new DataTable();
ad.Fill(dt);
grd.DataSource = dt;
CloseConnection();
}
}
}
//////////////
///// update butto code////
if (MetroFramework.MetroMessageBox.Show(this, "Do you want to Update this record?", "Alert", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) {
Database.DBGeneral obj = new Database.DBGeneral();
obj.General_Query("update TablePractice set Name='"+name.Text+"',FName='"+fname.Text+"',Cell='"+cell.Text+"',Email='"+email.Text+"' where ID='"+lbid.Text+"'");
MessageBox.Show("Record Updated Successfully!");
showRecords();
}
////////////////////////////////////////////////////
///////Delete button Record///////
if (MetroFramework.MetroMessageBox.Show(this, "Do you want to Delete this record?", "Alert", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
Database.DBGeneral obj = new Database.DBGeneral();
obj.General_Query("delete from TablePractice where ID='" + lbid.Text + "'");
MessageBox.Show("Record Deleted Successfully!");
showRecords();
}
//////////////////////////////////////////////////////
////ShowRecord Function//////
public void showRecords()
{
Database.DBGeneral obj = new Database.DBGeneral();
obj.DisplayData("select * from TablePractice order by ID DESC", myview);
}
//////////////////////////////////////////
/////End///////