C# (SHARP) AND MYSQL DATABASE CRUD - Insert, Update, Search, Delete and Display Data On DataGridView
C# (SHARP) AND MYSQL DATABASE CRUD - Insert, Update, Search, Delete and Display Data On DataGridView
Recent Comments
Table Of Contents
Archives
DEMO VIDEO
C# AND MYSQL DATABASE CRUD TUTORIAL #0 – How To Insert Update Search Delete And Display
Data On DataGridView – Demo Video (Overview) – Project Walk-Through
How To Create A New Form
New form gets created immediately and you can resize it by increasing
width and height. This can be done by dragging the edges or changing
the forms properties.
How To Create A New Form – New Form
In Solution Explorer, right click On Your Project Name And Select “Open
Project In Windows Explorer”. This is only when you want to know the
location where your c# project files are stored.
How To Create A New Form – Browse Folder Location
Form1.cs
1 using System; ?
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9
10 namespace CSHARPANDMYSQLDATABASE
11 {
12 public partial class Form1 : Form
13 {
14 public Form1()
15 {
16 InitializeComponent();
17 }
18 }
19 }
Form1.Designer.cs
1 namespace CSHARPANDMYSQLDATABASE ?
2 {
3 partial class Form1
4 {
5 /// <summary>
6 /// Required designer variable.
7 /// </summary>
8 private System.ComponentModel.IContaine
9
10 /// <summary>
11 /// Clean up any resources being used.
12 /// </summary>
13 /// <param name="disposing">true if man
14 protected override void Dispose(bool di
15 {
16 if (disposing && (components != nul
17 {
18 components.Dispose();
19 }
20 base.Dispose(disposing);
21 }
22
23 #region Windows Form Designer generated
24
25 /// <summary>
26 /// Required method for Designer suppor
27 /// the contents of this method with th
28 /// </summary>
29 private void InitializeComponent()
30 {
31 this.components = new System.Compon
32 this.AutoScaleMode = System.Windows
33 this.Text = "Form1";
34 }
35
36 #endregion
37 }
38 }
Program.cs
1 using System; ?
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Windows.Forms;
5
6 namespace CSHARPANDMYSQLDATABASE
7 {
8 static class Program
9 {
10 /// <summary>
11 /// The main entry point for the applic
12 /// </summary>
13 [STAThread]
14 static void Main()
15 {
16 Application.EnableVisualStyles();
17 Application.SetCompatibleTextRender
18 Application.Run(new Form1());
19 }
20 }
21 }
VIDEO TUTORIAL
C# AND MYSQL DATABASE CRUD TUTOR…
TUTOR…
Watch later Share
By default the project might not start at the center of the screen, to start
the window in the center screen, select it, then go to properties and set
start position to center screen.
How To Display The Form At The Center Screen
When you run the project it should start at the center of the screen.
How To Display The Form At The Center Screen Positioned
VIDEO TUTORIAL
VIDEO TUTORIAL
Select the form, then go to properties and click next to “BackColor” and
choose the desired color.
How To Change Or Set Form Background Color
VIDEO TUTORIAL
VIDEO TUTORIAL
VIDEO TUTORIAL
VIDEO TUTORIAL
VIDEO TUTORIAL
C# AND MYSQL DATABASE CRUD TUTOR…
TUTOR…
Watch later Share
VIDEO TUTORIAL
VIDEO TUTORIAL
VIDEO TUTORIAL
VIDEO TUTORIAL
C# AND MYSQL DATABASE CRUD TUTORIAL #12 – How To Add Picturebox On A Form
First you need to add image icons to your project resources folder.
Right Click On your project from solution explorer, and select properties.
How To Add Image Icon On A Button – Properties
check “Project resource file” radio button and select an icon from the
list. Then click Okay to add it on the button.
How To Add Image Icon On A Button – From Resources
VIDEO TUTORIAL
Browse button opens dialog box where you can choose image from your
computer.
C# SOURCE CODE
1 //Browse image from the copmputer and display ?i
2 private void button1_Click(object sender, Event
3 {
4 OpenFileDialog ofd = new OpenFileDialog();
5 //Filter Only Image with the following exte
6 ofd.Filter = "Choose Only Images|*.png;*.jp
7 //Dialog box title.
8 ofd.Title = "Choose Image";
9 //If Open Button from opened dialog box is
10 if (ofd.ShowDialog() == DialogResult.OK)
11 {
12 //Displaying image on picturebox.
13 pictureBox1.Image = Image.FromFile(ofd
14 //Displaying image path On Disabled tex
15 textBoxImagePath.Text = ofd.FileName;
16 //Getting Image Filename
17 textBoxImageName.Text = Path.GetFileNam
18 }
19 }
VIDEO TUTORIAL
C# AND MYSQL DATABASE CRUD TUTORIAL #14 – How To Browse And Display Image On
PictureBox
Click on picturebox to select it. Click on small right arrow icon located at
the top right of the picturebox.
How To Resize Image To Fit PictureBox
C# SOURCE CODE
1 this.pictureBox1.SizeMode = System.Windows.Forms
?
VIDEO TUTORIAL
C# SOURCE CODE
1 //Filter Only Image with the followin
?
VIDEO TUTORIAL
C# AND MYSQL DATABASE CRUD TUTORIAL #16 – How To Filter Image Types (Png, Jpg, Gif)
C# SOURCE CODE
1 //Displaying image path On Disabled textbox. ?
2 textBoxImagePath.Text = ofd.FileName;
C# SOURCE CODE
1 //Displaying image path On Disabled textbox. ?
2 textBoxImagePath.Text = ofd.FileName;
VIDEO TUTORIAL
Step 1. Go to https://dev.mysql.com/downloads/connector/net/
Select “.NET & Mono” from the dropdown list. Then Click Download
Button Next to Zip File.
How To Download Mysql Connector NET For Visual Studio C# Project
You can view the download progress by clicking the down arrow as
shown in the screenshot below. Am Using Mozilla FireFox Browser.
How To Download Mysql Connector NET For Visual Studio C# Project – Downloading
How To Download Mysql Connector NET For Visual Studio C# Project – Download Complete
Step 6 – Open any folder to check the files inside.
How To Download Mysql Connector NET For Visual Studio C# Project – File In Winrar
Step 10 – If you extracted the files in temp folder, copy them to another
location because this is a temporary folder. Anything stored here gets
deleted in case you wipe your PC. (With software like CCleaner).
How To Download Mysql Connector NET For Visual Studio C# Project – Copy Folder To Desired
Location
How To Download Mysql Connector NET For Visual Studio C# Project – Open Folder From Desktop
Step 12 – Here you can see mysql.data.dll file. This is the file you add to
your integrated development environment (IDE) like Visual Studio 2010.
How To Download Mysql Connector NET For Visual Studio C# Project – NET Connector File
VIDEO TUTORIAL
Select MySql.Data.Dll.
Click Ok.
How To Display Image Absolute Path OpenFileDialog – Browse Mysql Connector File
VIDEO TUTORIAL
On the left pane under created database, click on new, to create new
table.
Enter table name and add required columns and their datatypes.
How To Create New MySql Database Using PHPMyAdmin – Create New Table
To run a query for selecting all data from the table click on “SQL” tab.
SQL QUERY
1 -- phpMyAdmin SQL Dump ?
2 -- version 4.9.0.1
3 -- https://www.phpmyadmin.net/
4 --
5 -- Host: 127.0.0.1
6 -- Generation Time: Feb 20, 2020 at 02:46 PM
7 -- Server version: 10.3.15-MariaDB
8 -- PHP Version: 7.3.6
9
10 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
11 SET AUTOCOMMIT = 0;
12 START TRANSACTION;
13 SET time_zone = "+00:00";
14
15
16 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARAC
17 /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARA
18 /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLAT
19 /*!40101 SET NAMES utf8mb4 */;
20
21 --
22 -- Database: `csharpandmysqlcrudinsertupdatedel
23 --
24 CREATE DATABASE IF NOT EXISTS `csharpandmysqlcr
25 USE `csharpandmysqlcrudinsertupdatedeleteselect
26
27 -- --------------------------------------------
28
29 --
30 -- Table structure for table `csharpandmysqlcru
31 --
32
33 DROP TABLE IF EXISTS `csharpandmysqlcrudinsertu
34 CREATE TABLE IF NOT EXISTS `csharpandmysqlcrudi
35 `Id` int(11) NOT NULL AUTO_INCREMENT,
36 `FirstName` varchar(50) NOT NULL,
37 `LastName` varchar(50) NOT NULL,
38 `Email` varchar(50) NOT NULL,
39 `Gender` varchar(20) NOT NULL,
40 `Language` varchar(50) NOT NULL,
41 `Country` varchar(50) NOT NULL,
42 `ImageName` varchar(50) NOT NULL,
43 `ImagePath` varchar(255) NOT NULL,
44 `ImageBlob` longblob NOT NULL,
45 PRIMARY KEY (`Id`)
46 ) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARS
47
48 --
49 -- Dumping data for table `csharpandmysqlcrudin
50 --
51
52 COMMIT;
53
54 /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTE
55 /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACT
56 /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATIO
VIDEO TUTORIAL
C# AND MYSQL DATABASE CRUD TUTORIAL #19 – How To Create New MySql Database –
PHPMyAdmin
MySQLDatabaseConnection.cs
1 using System; ?
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using MySql.Data.MySqlClient;
6 using System.Data;
7 using System.Windows.Forms;
8
9 namespace JAVAANDMYSQLDATABASECRUD
10 {
11 public class MySQLDatabaseConnection
12 {
13 MySqlConnection connection = new MySqlC
14
15 //Function to get connection
16
17 public MySqlConnection getDatabaseConne
18 {
19 return connection;
20 }
21
22 //Open Connection function
23
24 public void openDBConnection() {
25 //Check if Connection Is Closed And
26 if (connection.State == ConnectionS
27 {
28 //MessageBox.Show("Connection O
29 connection.Open();
30 }
31 }
32
33 //Close Connection function
34
35 public void closeDBConnection()
36 {
37 //Check if Connection Is Open And C
38 if (connection.State == ConnectionS
39 {
40 //MessageBox.Show("Connection C
41 connection.Close();
42 }
43 }
44
45 }
46 }
VIDEO TUTORIAL
C# AND MYSQL DATABASE CRUD TUTORIAL #20 – How To Connect To MySql Database – Part 1
How To Connect To MySql Database – Part
2 .Net Framework 4.5.2 Download
When the download finishes, run the downloaded file and follow all the
steps till .Net Framework 4.5.2 is completely installed.
VIDEO TUTORIAL
How To Change The Target Framework In Visual Studio 2010 by updating the dot csproj Xml File –
Properties
Click on application tab and check the target framework. You can
choose different framework from the drop down list.
How To Change The Target Framework In Visual Studio 2010 by updating the dot csproj Xml File –
Target Framework
How To Change The Target Framework In Visual Studio 2010 by updating the dot csproj Xml File –
XML File
Save your settings then right click on project name and select “Reload
Project”.
How To Change The Target Framework In Visual Studio 2010 by updating the dot csproj Xml File –
Reload Project
VIDEO TUTORIAL
C# AND MYSQL DATABASE CRUD TUTORIAL #22 – How To Connect To MySql Database – Part 3
Changing The Target Framework
How To Connect To MySql Database – Part
4 – Check Connection [XAMPP]
VIDEO TUTORIAL
C# AND MYSQL DATABASE CRUD TUTORIAL #23 – How To Connect To MySql Database – Part 4 –
Check Connection [XAMPP]
How To Connect To MySql Database – Part
5 Opening Connection Function
C# SOURCE CODE
1 //Open Connection function ?
2
3 public void openDBConnection() {
4 //Check if Connection Is Closed And Open It
5 if (connection.State == ConnectionState.Clo
6 {
7 //MessageBox.Show("Connection Opened");
8 connection.Open();
9 }
10 }
VIDEO TUTORIAL
C# SOURCE CODE
1 //Close Connection function ?
2
3 public void closeDBConnection()
4 {
5 //Check if Connection Is Open And Close It
6 if (connection.State == ConnectionState.Ope
7 {
8 //MessageBox.Show("Connection Closed");
9 connection.Close();
10 }
11 }
VIDEO TUTORIAL
C# AND MYSQL DATABASE CRUD TUTORIAL #25 – How To Connect To MySql Database – Part 6
Closing Connection Function
VIDEO TUTORIAL
C# AND MYSQL TUTORIAL #27 - How To I…
I…
Watch later Share
C# AND MYSQL DATABASE CRUD TUTORIAL #26 – How To Insert TextBox Text Or Value Or Data Into
MySql Database – Part 1
C# SOURCE CODE
1 //Getting Image Filename ?
2 textBoxImageName.Text = Path.GetFileName(ofd.Fil
VIDEO TUTORIAL
C# AND MYSQL TUTORIAL #28 - How To …
Watch later Share
C# AND MYSQL DATABASE CRUD TUTORIAL #28 – How To Obtain Only The Filename
(OpenFileDialog) Insert Into Db – Part 3
VIDEO TUTORIAL
C# AND MYSQL DATABASE CRUD TUTORIAL #30 – How To Insert Checkbox Values Or Data Into
Database
VIDEO TUTORIAL
C# AND MYSQL DATABASE CRUD TUTORIAL #32 – How To Save Or Insert Image Into Mysql
Database
All rows are displayed In DataGridView from Mysql table when you run
the application. Also the datagridview refreshes when you : insert new
row(data), delete a row, update a row etc…..
Person.cs
1 using System; ?
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5
6 namespace JAVAANDMYSQLDATABASECRUD
7 {
8 class Person
9 {
10 //Shortcut For Creating properties and
11 // Type propfull and double click Tab
12
13 private int _Id;
14 private string _FirstName;
15 private string _LastName;
16 private string _Email;
17 private string _Gender;
18 private string _Language;
19 private string _Country;
20 private string _ImageName;
21 private string _ImagePath;
22 private byte[] _ImageBlob;
23
24
25 //To create Constructor Type ctor, then
26 public Person()
27 {
28
29 }
30
31 public int Id
32 {
33 get { return _Id; }
34 set { _Id = value; }
35 }
36
37 public string FirstName
38 {
39 get { return _FirstName; }
40 set { _FirstName = value; }
41 }
42
43 public string LastName
44 {
45 get { return _LastName; }
46 set { _LastName = value; }
47 }
48
49 public string Email
50 {
51 get { return _Email; }
52 set { _Email = value; }
53 }
54
55 public string Gender
56 {
57 get { return _Gender; }
58 set { _Gender = value; }
59 }
60
61 public string Language
62 {
63 get { return _Language; }
64 set { _Language = value; }
65 }
66
67 public string Country
68 {
69 get { return _Country; }
70 set { _Country = value; }
71 }
72
73 public string ImageName
74 {
75 get { return _ImageName; }
76 set { _ImageName = value; }
77 }
78
79 public string ImagePath
80 {
81 get { return _ImagePath; }
82 set { _ImagePath = value; }
83 }
84
85 public byte[] ImageBlob
86 {
87 get { return _ImageBlob; }
88 set { _ImageBlob = value; }
89 }
90
91
92 }
93 }
PersonData.cs
1 using System; ?
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Windows.Forms;
6 using MySql.Data.MySqlClient;
7
8 namespace JAVAANDMYSQLDATABASECRUD
9 {
10 class PersonData
11 {
12 MySQLDatabaseConnection dbCONN = new My
13 public List<Person> PersonList(string v
14 {
15
16 List<Person> personList = new List<
17 String selectFromMysqlDatabase = "S
18 MySqlCommand command;
19 MySqlDataReader reader;
20 Person person;
21
22 dbCONN.openDBConnection();
23 try
24 {
25 command = new MySqlCommand(sele
26 reader = command.ExecuteReader
27
28 while (reader.Read())
29 {
30 person = new Person();
31 person.Id = Convert.ToInt32
32 //.GetInt32(reader[0].T
33 person.FirstName = reader[1
34 person.LastName = reader[2]
35 person.Email = reader[3].To
36 person.Gender = reader[4].T
37 person.Language = reader[5]
38 person.Country = reader[6]
39 person.ImageName = reader[7
40 person.ImagePath = reader[8
41 person.ImageBlob = (byte[])
42
43 personList.Add(person);
44 }
45 }
46 catch (Exception err)
47 {
48 MessageBox.Show("Error " + err
49 }
50 finally
51 {
52 //reader.Close();
53 //command.Dispose();
54 dbCONN.closeDBConnection();
55
56 }
57
58 return personList;
59
60 }
61 }
62 }
C# SOURCE CODE
1 private void Form1_Load(object sender, EventArg
?
2 {
3 //Fill Datagridview with data from mysql da
4 refreshDatagridView("");
5
6 }
7
8 private void refreshDatagridView(string searchV
9 {
10 dataGridView1.AutoSizeColumnsMode = DataGri
11 dataGridView1.RowTemplate.Height = 45;
12
13 BindingSource bsource = new BindingSource()
14 PersonData pData = new PersonData();
15 bsource.DataSource = pData.PersonList(searc
16 dataGridView1.DataSource = bsource;
17
18 //Fit Image In DataGridView Cell
19 DataGridViewImageColumn dGVimageColumn = (D
20 dGVimageColumn.ImageLayout = DataGridViewIm
21 }
How To Retrieve Data From Mysql And Display It On DataGridView In C
VIDEO TUTORIAL
C# SOURCE CODE
1 this.dataGridView1.AutoSizeColumnsMode = System?
VIDEO TUTORIAL
C# SOURCE CODE
1 dataGridView1.RowTemplate.Height = 45; ?
VIDEO TUTORIAL
VIDEO TUTORIAL
Getters, setters and constructors simplify the whole coding process and
reduce the code.
C# SOURCE CODE
1 using System; ?
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5
6 namespace JAVAANDMYSQLDATABASECRUD
7 {
8 class Person
9 {
10 //Shortcut For Creating properties and
11 // Type propfull and double click Tab
12
13 private int _Id;
14 private string _FirstName;
15 private string _LastName;
16 private string _Email;
17 private string _Gender;
18 private string _Language;
19 private string _Country;
20 private string _ImageName;
21 private string _ImagePath;
22 private byte[] _ImageBlob;
23
24
25 //To create Constructor Type ctor, then
26 public Person()
27 {
28
29 }
30
31 public int Id
32 {
33 get { return _Id; }
34 set { _Id = value; }
35 }
36
37 public string FirstName
38 {
39 get { return _FirstName; }
40 set { _FirstName = value; }
41 }
42
43 public string LastName
44 {
45 get { return _LastName; }
46 set { _LastName = value; }
47 }
48
49 public string Email
50 {
51 get { return _Email; }
52 set { _Email = value; }
53 }
54
55 public string Gender
56 {
57 get { return _Gender; }
58 set { _Gender = value; }
59 }
60
61 public string Language
62 {
63 get { return _Language; }
64 set { _Language = value; }
65 }
66
67 public string Country
68 {
69 get { return _Country; }
70 set { _Country = value; }
71 }
72
73 public string ImageName
74 {
75 get { return _ImageName; }
76 set { _ImageName = value; }
77 }
78
79 public string ImagePath
80 {
81 get { return _ImagePath; }
82 set { _ImagePath = value; }
83 }
84
85 public byte[] ImageBlob
86 {
87 get { return _ImageBlob; }
88 set { _ImageBlob = value; }
89 }
90
91
92 }
93 }
VIDEO TUTORIAL
C# AND MYSQL DATABASE CRUD TUTORIAL #37 – How To Create Getters Setters And Constructor
– Shortcut
How To Read Mysql Data And Store Them
In Array List C#
C# SOURCE CODE
1 using System; ?
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Windows.Forms;
6 using MySql.Data.MySqlClient;
7
8 namespace JAVAANDMYSQLDATABASECRUD
9 {
10 class PersonData
11 {
12 MySQLDatabaseConnection dbCONN = new My
13 public List<Person> PersonList(string v
14 {
15
16 List<Person> personList = new List<
17 String selectFromMysqlDatabase = "S
18 MySqlCommand command;
19 MySqlDataReader reader;
20 Person person;
21
22 dbCONN.openDBConnection();
23 try
24 {
25 command = new MySqlCommand(sele
26 reader = command.ExecuteReader
27
28 while (reader.Read())
29 {
30 person = new Person();
31 person.Id = Convert.ToInt32
32 //.GetInt32(reader[0].T
33 person.FirstName = reader[1
34 person.LastName = reader[2]
35 person.Email = reader[3].To
36 person.Gender = reader[4].T
37 person.Language = reader[5]
38 person.Country = reader[6]
39 person.ImageName = reader[7
40 person.ImagePath = reader[8
41 person.ImageBlob = (byte[])
42
43 personList.Add(person);
44 }
45 }
46 catch (Exception err)
47 {
48 MessageBox.Show("Error " + err
49 }
50 finally
51 {
52 //reader.Close();
53 //command.Dispose();
54 dbCONN.closeDBConnection();
55
56 }
57
58 return personList;
59
60 }
61 }
62 }
VIDEO TUTORIAL
C# AND MYSQL DATABASE CRUD TUTORIAL #38 – How To Read Mysql Rows(Data) And Store
Them In Array List
C# SOURCE CODE
1 private void refreshDatagridView(string searchV
?
2 {
3 dataGridView1.AutoSizeColumnsMode = DataGri
4 dataGridView1.RowTemplate.Height = 45;
5
6 BindingSource bsource = new BindingSource()
7 PersonData pData = new PersonData();
8 bsource.DataSource = pData.PersonList(searc
9 dataGridView1.DataSource = bsource;
10
11 //Fit Image In DataGridView Cell
12 DataGridViewImageColumn dGVimageColumn = (D
13 dGVimageColumn.ImageLayout = DataGridViewIm
14 }
VIDEO TUTORIAL
C# AND MYSQL DATABASE CRUD TUTORIAL #39 – How To Populate (Bind) Datagridview From List
Of Items
How To Move a Line(Selected Code) Up or
Down in Visual Studio
You can easily move lines up and down using MoveLine Extension.
Download Link – https://marketplace.visualstudio.com/items?
itemName=KevinAenmey.MoveLine
How to Move Selected Code Up or Down in Visual Studio – Homepage
Step 1. Go Tools
How to Move Selected Code Up or Down in Visual Studio – Tools
Step 4. Type The name of the extension in the search box. In this Case
“MoveLine”;
How to Move Selected Code Up or Down in Visual Studio – Search MoveLine
If you go back to extension manager, you will see that the extension has
been added.
How to Move Selected Code Up or Down in Visual Studio – Installed
To move single line or selected block of code (Multiple Lines) use the
keyboard shortcuts below.
VIDEO TUTORIAL
C# AND MYSQL DATABASE CRUD TUTORIAL #40 – How to Move a Line(Selected Code) Up or Down
in Visual Studio
How To Check If Datagridview Row Is
Selected Or Not In C#
VIDEO TUTORIAL
C# AND MYSQL DATABASE CRUD TUTORIAL #41 – How To Check If Datagridview Row Is Selected
Or Not
How To Get Datagridview Currently
Selected Row Index On Row click C#
VIDEO TUTORIAL
C# AND MYSQL DATABASE CRUD TUTORIAL #42 – How To Get Datagridview Currently Selected
Row Index On Row click
How To Display Selected Row From
Datagridview To Textboxes In C#
C# SOURCE CODE
1 private void dataGridView1_CellClick(object sen
?
2 {
3 //Check If there is a row selected
4
5 if (dataGridView1.SelectedRows.Count > 0)
6 {
7 selectedRowIndex = e.RowIndex;
8 // Selected Row
9 //MessageBox.Show("Selected Row Index >
10
11 DataGridViewRow selectedDGVRow = dataGr
12 //Diplaying Selected DataGridView row d
13 textBoxID.Text = selectedDGVRow.Cells[0
14 textBoxFirstName.Text = selectedDGVRow
15 textBoxLastName.Text = selectedDGVRow.C
16 textBoxEmail.Text = selectedDGVRow.Cell
17 //Check if datagridview cell value matc
18 if (selectedDGVRow.Cells[4].Value.ToStr
19 {
20 //Diplaying Selected DataGridView r
21 radioButtonMale.Checked = true;
22 }
23 else
24 if (selectedDGVRow.Cells[4].Value.T
25 {
26 //Diplaying Selected DataGridVi
27 radioButtonFemale.Checked = tru
28 }
29 if (selectedDGVRow.Cells[5].Value.ToStr
30 {
31 //Diplaying Selected DataGridView r
32 checkBoxEnglish.Checked = true;
33 }
34 else
35 if (selectedDGVRow.Cells[5].Value.T
36 {
37 //Diplaying Selected DataGridVi
38 checkBoxArabic.Checked = true;
39 }
40
41 comboBoxCountry.Text = selectedDGVRow.C
42 textBoxImageName.Text = selectedDGVRow
43 textBoxImagePath.Text = selectedDGVRow
44 //Diplaying Selected DataGridView row d
45 byte[] imgB = (byte[])selectedDGVRow.Ce
46 MemoryStream ms = new MemoryStream(imgB
47 pictureBox1.Image = Image.FromStream(ms
48 }
49 else
50 {
51
52 //No Row Selected
53 }
54 }
How To Get Datagridview Currently Selected Row Index On Row click C
VIDEO TUTORIAL
C# SOURCE CODE
1 private void dataGridView1_CellClick(object sen
?
2 {
3 //Check If there is a row selected
4
5 if (dataGridView1.SelectedRows.Count > 0)
6 {
7 selectedRowIndex = e.RowIndex;
8 // Selected Row
9 //MessageBox.Show("Selected Row Index >
10
11 DataGridViewRow selectedDGVRow = dataGr
12 //Diplaying Selected DataGridView row d
13 textBoxID.Text = selectedDGVRow.Cells[0
14 textBoxFirstName.Text = selectedDGVRow
15 textBoxLastName.Text = selectedDGVRow.C
16 textBoxEmail.Text = selectedDGVRow.Cell
17 //Check if datagridview cell value matc
18 if (selectedDGVRow.Cells[4].Value.ToStr
19 {
20 //Diplaying Selected DataGridView r
21 radioButtonMale.Checked = true;
22 }
23 else
24 if (selectedDGVRow.Cells[4].Value.T
25 {
26 //Diplaying Selected DataGridVi
27 radioButtonFemale.Checked = tru
28 }
29 if (selectedDGVRow.Cells[5].Value.ToStr
30 {
31 //Diplaying Selected DataGridView r
32 checkBoxEnglish.Checked = true;
33 }
34 else
35 if (selectedDGVRow.Cells[5].Value.T
36 {
37 //Diplaying Selected DataGridVi
38 checkBoxArabic.Checked = true;
39 }
40
41 comboBoxCountry.Text = selectedDGVRow.C
42 textBoxImageName.Text = selectedDGVRow
43 textBoxImagePath.Text = selectedDGVRow
44 //Diplaying Selected DataGridView row d
45 byte[] imgB = (byte[])selectedDGVRow.Ce
46 MemoryStream ms = new MemoryStream(imgB
47 pictureBox1.Image = Image.FromStream(ms
48 }
49 else
50 {
51
52 //No Row Selected
53 }
54 }
How To Display Selected Row Image From Datagridview To Picturebox C
VIDEO TUTORIAL
Radio button gets selected when you click on datagridview row with the
value that matches radio button value.
C# SOURCE CODE
1 private void dataGridView1_CellClick(object sen
?
2 {
3 //Check If there is a row selected
4
5 if (dataGridView1.SelectedRows.Count > 0)
6 {
7 selectedRowIndex = e.RowIndex;
8 // Selected Row
9 //MessageBox.Show("Selected Row Index >
10
11 DataGridViewRow selectedDGVRow = dataGr
12 //Diplaying Selected DataGridView row d
13 textBoxID.Text = selectedDGVRow.Cells[0
14 textBoxFirstName.Text = selectedDGVRow
15 textBoxLastName.Text = selectedDGVRow.C
16 textBoxEmail.Text = selectedDGVRow.Cell
17 //Check if datagridview cell value matc
18 if (selectedDGVRow.Cells[4].Value.ToStr
19 {
20 //Diplaying Selected DataGridView r
21 radioButtonMale.Checked = true;
22 }
23 else
24 if (selectedDGVRow.Cells[4].Value.T
25 {
26 //Diplaying Selected DataGridVi
27 radioButtonFemale.Checked = tru
28 }
29 if (selectedDGVRow.Cells[5].Value.ToStr
30 {
31 //Diplaying Selected DataGridView r
32 checkBoxEnglish.Checked = true;
33 }
34 else
35 if (selectedDGVRow.Cells[5].Value.T
36 {
37 //Diplaying Selected DataGridVi
38 checkBoxArabic.Checked = true;
39 }
40
41 comboBoxCountry.Text = selectedDGVRow.C
42 textBoxImageName.Text = selectedDGVRow
43 textBoxImagePath.Text = selectedDGVRow
44 //Diplaying Selected DataGridView row d
45 byte[] imgB = (byte[])selectedDGVRow.Ce
46 MemoryStream ms = new MemoryStream(imgB
47 pictureBox1.Image = Image.FromStream(ms
48 }
49 else
50 {
51
52 //No Row Selected
53 }
54 }
How To Display Selected Row Value From Datagridview To RadioButton C
VIDEO TUTORIAL
CheckBox gets checked when you click on datagridview row with the
value that matches CheckBox value.
C# SOURCE CODE
1 private void dataGridView1_CellClick(object sen
?
2 {
3 //Check If there is a row selected
4
5 if (dataGridView1.SelectedRows.Count > 0)
6 {
7 selectedRowIndex = e.RowIndex;
8 // Selected Row
9 //MessageBox.Show("Selected Row Index >
10
11 DataGridViewRow selectedDGVRow = dataGr
12 //Diplaying Selected DataGridView row d
13 textBoxID.Text = selectedDGVRow.Cells[0
14 textBoxFirstName.Text = selectedDGVRow
15 textBoxLastName.Text = selectedDGVRow.C
16 textBoxEmail.Text = selectedDGVRow.Cell
17 //Check if datagridview cell value matc
18 if (selectedDGVRow.Cells[4].Value.ToStr
19 {
20 //Diplaying Selected DataGridView r
21 radioButtonMale.Checked = true;
22 }
23 else
24 if (selectedDGVRow.Cells[4].Value.T
25 {
26 //Diplaying Selected DataGridVi
27 radioButtonFemale.Checked = tru
28 }
29 if (selectedDGVRow.Cells[5].Value.ToStr
30 {
31 //Diplaying Selected DataGridView r
32 checkBoxEnglish.Checked = true;
33 }
34 else
35 if (selectedDGVRow.Cells[5].Value.T
36 {
37 //Diplaying Selected DataGridVi
38 checkBoxArabic.Checked = true;
39 }
40
41 comboBoxCountry.Text = selectedDGVRow.C
42 textBoxImageName.Text = selectedDGVRow
43 textBoxImagePath.Text = selectedDGVRow
44 //Diplaying Selected DataGridView row d
45 byte[] imgB = (byte[])selectedDGVRow.Ce
46 MemoryStream ms = new MemoryStream(imgB
47 pictureBox1.Image = Image.FromStream(ms
48 }
49 else
50 {
51
52 //No Row Selected
53 }
54 }
How To Display Selected Row Value From Datagridview To CheckBox C
VIDEO TUTORIAL
C# SOURCE CODE
1 private void dataGridView1_CellClick(object sen
?
2 {
3 //Check If there is a row selected
4
5 if (dataGridView1.SelectedRows.Count > 0)
6 {
7 selectedRowIndex = e.RowIndex;
8 // Selected Row
9 //MessageBox.Show("Selected Row Index >
10
11 DataGridViewRow selectedDGVRow = dataGr
12 //Diplaying Selected DataGridView row d
13 textBoxID.Text = selectedDGVRow.Cells[0
14 textBoxFirstName.Text = selectedDGVRow
15 textBoxLastName.Text = selectedDGVRow.C
16 textBoxEmail.Text = selectedDGVRow.Cell
17 //Check if datagridview cell value matc
18 if (selectedDGVRow.Cells[4].Value.ToStr
19 {
20 //Diplaying Selected DataGridView r
21 radioButtonMale.Checked = true;
22 }
23 else
24 if (selectedDGVRow.Cells[4].Value.T
25 {
26 //Diplaying Selected DataGridVi
27 radioButtonFemale.Checked = tru
28 }
29 if (selectedDGVRow.Cells[5].Value.ToStr
30 {
31 //Diplaying Selected DataGridView r
32 checkBoxEnglish.Checked = true;
33 }
34 else
35 if (selectedDGVRow.Cells[5].Value.T
36 {
37 //Diplaying Selected DataGridVi
38 checkBoxArabic.Checked = true;
39 }
40
41 comboBoxCountry.Text = selectedDGVRow.C
42 textBoxImageName.Text = selectedDGVRow
43 textBoxImagePath.Text = selectedDGVRow
44 //Diplaying Selected DataGridView row d
45 byte[] imgB = (byte[])selectedDGVRow.Ce
46 MemoryStream ms = new MemoryStream(imgB
47 pictureBox1.Image = Image.FromStream(ms
48 }
49 else
50 {
51
52 //No Row Selected
53 }
54 }
How To Display Selected Row Value From Datagridview To ComboBox C
VIDEO TUTORIAL
VIDEO TUTORIAL
C# SOURCE CODE
1 //Resetting/Clearing Textfields Function ?
VIDEO TUTORIAL
C# SOURCE CODE
1 //Resetting/Clearing Textfields Function ?
VIDEO TUTORIAL
Clearing all textbox values on button click. Empty values are assigned to
Textbox in this scenario.
How To clear Or Reset Text Boxes On Button Click In C
C# SOURCE CODE
1 //Resetting/Clearing Textfields Function ?
VIDEO TUTORIAL
Clearing image from picture box on button click. This sets value of a
picture box Image to null.
How To clear Or Reset Image On A Picturebox On Button Click In C
C# SOURCE CODE
1 //Resetting/Clearing Textfields Function ?
VIDEO TUTORIAL
C# SOURCE CODE
1 //Resetting/Clearing Textfields Function ?
VIDEO TUTORIAL
VIDEO TUTORIAL
Checking if input fields are empty before inserting their values to the
database. If one of the field is blank you will not be able to insert data
into the database.
C# SOURCE CODE
1 if (string.IsNullOrEmpty(textBoxFirstName.Text)?
2 {
3 //If there is one or more empty fields outpu
4 MessageBox.Show("one or more empty fields. F
5
6 }
VIDEO TUTORIAL
C# SOURCE CODE
1 //Deleting data from mysql database ?
VIDEO TUTORIAL
C# SOURCE CODE
1 //CALLING THIS FUNCTION REFRESHES DATAGRIDVIEW?
2 private void refreshDatagridView(string
3 {
4 dataGridView1.AutoSizeColumnsMode =
5 dataGridView1.RowTemplate.Height =
6
7 BindingSource bsource = new Binding
8 PersonData pData = new PersonData()
9 bsource.DataSource = pData.PersonLi
10 dataGridView1.DataSource = bsource;
11
12 //Fit Image In DataGridView Cell
13 DataGridViewImageColumn dGVimageCol
14 dGVimageColumn.ImageLayout = DataGr
15 }
VIDEO TUTORIAL
C# AND MYSQL DATABASE CRUD TUTORIAL #57 – How To Refresh Datagridview Rows After
Change In MySql
C# SOURCE CODE
1 //Updating Mysql Database Row ?
VIDEO TUTORIAL
C# AND MYSQL DATABASE CRUD TUTORIAL #58 – How To Update Data From Table In MySql
To search for a specific data enter the keywords in the search textbox.
Datagridview displays data that matches your keyword on keypress.
How To Search Data From MySql and Filter in datagridview Table In C
C# SOURCE CODE
1 private void textBox1_KeyUp(object sender, KeyEv
?
2 {
3 string val = textBoxSearch.Text;
4 refreshDatagridView(val);
5 }
VIDEO TUTORIAL
VIDEO TUTORIAL
C# AND MYSQL DATABASE CRUD TUTORIAL #61 – Insert Update Search Delete And Display Data
On DataGridView Using Visual Studio 2010 Complete Video Tutorial
Tags: C# Form Application, Database (Software Genre), localhost, mysql database, XAMPP
Published by admin
Prev Next
C SHARP AND MYSQL DATABASE How To Download Mysql Connector
CRUD TUTORIAL 61 How To Insert For Visual Studio C Sharp Project
Update Search Delete And Display
Data On DataGridView Complete
Video Tutorial
Leave a Reply
Your email address will not be published. Required fields are marked *
Comment
Name *
Email *
Website
Save my name, email, and website in this browser for the next time I comment.
POST COMMENT
© Copyright 2020 – Maurice Muteti
Allium Theme by TemplateLens ⋅ Powered by WordPress
PDFmyURL.com - convert URLs, web pages or even full websites to PDF online. Easy API for developers!