Skip to main content

Posts

Showing posts with the label C# Programming

Login in asp.net using C# by webconfig file

Below is the code which will demonstrate how to design login functionality in asp.net using C# by with the help of web configuration file. Please note the login details are used as a static. The Web configuration file is:                                   The below is the design view of the project: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="ShoppingHeart.Admin.Login" %>                                                                                Style="font-weight: 700">                                 ...

Cookie example in C# Asp.net

Below is the program which will show you how to maintain user page visit counts for web page using cookies. After each manual page refresh the count goes on increasing. Here us the code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace cookie_example {     public partial class WebForm1 : System.Web.UI.Page     {         protected void Page_Load(object sender, EventArgs e)         {             int x = 0;             try             {                 HttpCookie c = Request.Cookies["mycookie"];                 if(c!= null)                 {                   ...

Maintain user page visit counts in C# asp.net

Below is the program which will show you how to maintain user page visit counts for web page. After each manual page refresh the count goes on increasing. Here us the code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace show_user_visit_count_demo {     public partial class WebForm1 : System.Web.UI.Page     {                     protected void Page_Load(object sender, EventArgs e)         {             int x = 0;             try             {                 if(Session["cnt"]==null)                 {                     x = 0;         ...

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 ...

Add, remove, search an item in listview in C#

Below is the C# code which will help you to add, remove and search operations on listview control in C#. 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; namespace Treeview_control_demo {     public partial class Form2 : Form     {         public Form2()         {             InitializeComponent();             listView1.View = View.Details;                   }         private void button1_Click(object sender, EventArgs e)         {             if (textBox1.Text.Trim().Length == 0)...

Employee Salary calculator windows project in C#

Below is the window project in c# which calculates the net salary of the employee. It takes employee id, name and designation as input and calculates the salary according to the designation of the employee. The project has static data. I have not implemented a database for storing data. in future will share projects who will have database to store data. Thanks for visiting my blog. I will try to make this blog is best source of learning for you.     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; namespace Employee_Salary_calculator_demo {     public partial class Form1 : Form     {         int empno;         String name;       ...

Treeview control demo in C#

Below is the code which shows treeview control demo in c#. It has a treeview control and a label. If we select any node on treeview, the label is showing named corresponding selected name of the node of treeview. 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; namespace Treeview_control_demo {     public partial class Form1 : Form     {         public Form1()         {             InitializeComponent();         }         private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)         {             label1.Text = treeVie...

RGB Color Demo in C# using scrollbar as a slider horizontally

Below is the project which contains 3 horizontal scrollbars if we slides the scrollbars the background color of the form is changing accordingly. first scrollbar is adding red color, second adding green and third one adding blue upon scrolling or sliding. Take 3 horizontal scrollbars and assign them maximum value of 255(from 0) to each one. Below is the designer 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; namespace Color_RGB_demo {     public partial class Form1 : Form     {         public Form1()         {             InitializeComponent();                   }         public...

Student Marksheet with grades windows form project in C# demo

Student Mark-sheet windows form in C# demo Below is the program which takes students name, marks of 6 subjects as an input. After a button click it will display result either PASS, FAIL or ATKT (for 2 backlogs).  Below is the design view of the project: Below is the windows C# 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; namespace marksheet_demo {     public partial class Form1 : Form     {         int m1, m2, m3, m4, m5, m6, total;         float per;         String name, grade, result;         public Form1()         {        ...

Mini C# project of math game demo

Mini project of math game in C# demo Assignment: Below is the very small project. It contains a button after clicking that it will internally generate a random number between 1 to 100 range only and we have to guess that number and if we success it will show the number of attempts we required to guess that number. Below is the design view of the projects contains two screens: HERE IS THE 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; namespace generate_random_number_demo {     public partial class Form1 : Form     {         int x = 0, att = 0;         Random r1 = new Random();         public Form1()         {             InitializeComponent();   ...