Skip to main content

Posts

Showing posts from September, 2017

Display all procedure names of a database schema into treeview

Below is the project which shows all the existing procedure names in any particular database schema into a tree-view control. We have used a class library "stored_proc_db_disp_dll" and imported it's reference into a windows project. The class library contains a function "DisplayProcedures()" which returns a list collection containing all procedure names of a database schema and windows project binds that list to tree-view control. Below is the design view of the project:                             Tree-view displaying all procedure names of a db schema Here is code for class library: namespace stored_proc_db_disp_dll {     public class Class1     {         MySqlConnection con = new MySqlConnection("server=localhost;uid=root;pwd=root;database=test");         MySqlCommand cmd=null;         MySqlDataReader dr; publ...

Treeview control showing all table names in a database schema

Below is the project which shows all the existing table names in any particular database schema into a tree-view control. We have used a class library "stored_proc_db_disp_dll" and imported it's reference into a windows project. The class library contains a function "DisplayTables()" which returns a list collection containing all table names of a database schema and windows project binds that list to tree-view control. Below is the design view of the project: Tree-view displaying all table names of a schema Here is code for class library: namespace stored_proc_db_disp_dll {     public class Class1     {         MySqlConnection con = new MySqlConnection("server=localhost;uid=root;pwd=root;database=test");         MySqlCommand cmd=null;         MySqlDataReader dr; public List DisplayTables()         {             DataTable dt = new Da...

Login in C# using mysql

Below is the c# project which shows how to implement login functionlity using mysql database as backend. Design view of the project: Login Screen Source of the project: using System.Windows.Forms; using MySql.Data.MySqlClient; namespace WindowsFormsApplication1 {     public partial class Form1 : Form     {         MySqlConnection con = new MySqlConnection("server=localhost;uid=root;pwd=root;database=test");         MySqlCommand cmd;         MySqlDataReader dr;                         public Form1()         {             InitializeComponent();             cmd = new MySqlCommand();             cmd.Connection = con;             try             {  ...

create stoared procedure in C#

Following is the project in C# which creates a stoared procedure in mysql database. for that we created a class library and we import this in one windows project. using MySql.Data.MySqlClient; using System.Data; namespace stored_proc_db_disp_dll {     public class Class1     {         MySqlConnection con = new MySqlConnection("server=localhost;uid=root;pwd=root;database=test");         MySqlCommand cmd=null;         MySqlDataReader dr;         public Boolean createprocedure(String str)         {             bool b = true;             try             {                 cmd.CommandText = str;                 cmd.ExecuteNonQuery();             } ...

navigate records in datagridview

Below is the code which will show how to navigate between datagridview records like first, last, previous and next record.                private void button1_Click(object sender, EventArgs e)         {             //first             int i = 0;             this.dataGridView1.CurrentCell = dataGridView1.Rows[0].Cells[dataGridView1.CurrentCell.ColumnIndex];         }         private void button2_Click(object sender, EventArgs e)         {             //previous             int prev = dataGridView1.CurrentRow.Index - 1;             if (prev >= 0)             {                 this.dataGridView1.CurrentCell ...

save Datagridview record to csv file

Below is the function which is written in C#, which will demonstrates how to save all datagridview record into CSV(Comma separated file). public void ExportGridToCSV()         {             string filename = "";             SaveFileDialog sfd = new SaveFileDialog();             sfd.Filter = "CSV (*.csv)|*.csv";             sfd.FileName = "Output.csv";             if (sfd.ShowDialog() == DialogResult.OK)             {                 MessageBox.Show("Data will be exported and you will be notified when it is ready.");                 if (File.Exists(filename))                 {                     try   ...

Insert, update, delete, display, navigate in datagridview and download datagridview data in csv file

Insert, update, delete, display, navigate in datagridview and download datagridview data in csv file using C# Below is the project which will demonstrates 1) how to insert, update, delete and display data in datagridview in C#. Also, 2) it will show navigate to records like navigate to first, last, previous and next record. In addition, 3) If we click on any record present in datagridview then it will display the corresponding record in number of textboxes. And Finally and most           important, 4) It will save all the records into csv file. Below is the Design view of the project: Below is the source code of the project: 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 System.IO; using MySql.Data.MySqlClient; namespace my_first_database_demo {    ...

display files and directories in Listview

Below is the C# code which displays all files and directories in listview control with their file size and creation date. If it is file then it also displays the extension of the file e.g. .txt, .jpg etc Below is the design view of the project: Listview to display files and directories with size and date created Below is the source code of the project: 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 System.IO; namespace search_in_listview {     public partial class Form1 : Form     {         public Form1()         {             InitializeComponent();                   }         private void button1_Click(object sender, EventArgs ...