Programming for Everybody: October 2021

insert update delete search and print in sql server databse using C# [with 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 System.Data.SqlClient;

namespace Insert_update_delete_search_and_print_in_sql

{

    public partial class Form2 : Form

    {

        public Form2()

        {

            InitializeComponent();

        }

        SqlConnection conn = new SqlConnection("Data source=.;initial catalog=database3;integrated security=true");

        private void Form2_Load(object sender, EventArgs e)

        {

            bind_data();

        }

        private void bind_data()

        {

            SqlCommand cmd1 = new SqlCommand("Select id,fname As firstname,lname As Lastname,sum from Table1", conn);

            SqlDataAdapter da = new SqlDataAdapter();

            da.SelectCommand = cmd1;

            DataTable dt = new DataTable();

            dt.Clear();

            da.Fill(dt);

            dataGridView1.DataSource = dt;

            dataGridView1.ColumnHeadersDefaultCellStyle.Font = new Font("Tahoma", 12, FontStyle.Bold);

            dataGridView1.DefaultCellStyle.Font = new Font("arial", 12);

        }


        private void button1_Click(object sender, EventArgs e)

        {

            SqlCommand cmd2 = new SqlCommand("Insert into Table1(id,fname,lname,sum)Values(@id,@firstname,@lastname,@sum)", conn);

            cmd2.Parameters.AddWithValue("id", textBox1.Text);

            cmd2.Parameters.AddWithValue("firstname", textBox2.Text);

            cmd2.Parameters.AddWithValue("lastname", textBox3.Text);

            cmd2.Parameters.AddWithValue("sum", textBox4.Text);

            conn.Open();

            cmd2.ExecuteNonQuery();

            conn.Close();

            bind_data();


        }


        private void button2_Click(object sender, EventArgs e)

        {

            textBox1.Text = "";

            textBox2.Text = "";

            textBox3.Text = "";

            textBox4.Text = "";


        }


        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)

        {

            int index;

            index = e.RowIndex;

            DataGridViewRow selectedrow = dataGridView1.Rows[index];

            textBox1.Text = selectedrow.Cells[0].Value.ToString();

            textBox2.Text = selectedrow.Cells[1].Value.ToString();

            textBox3.Text = selectedrow.Cells[2].Value.ToString();

            textBox4.Text = selectedrow.Cells[3].Value.ToString();



        }


        private void button3_Click(object sender, EventArgs e)

        {

            SqlCommand cmd3 = new SqlCommand("Update Table1 Set fname=@firstname,lname=@lastname,sum=@sum where id=@id", conn);


            

            cmd3.Parameters.AddWithValue("firstname", textBox2.Text);

            cmd3.Parameters.AddWithValue("lastname", textBox3.Text);

            cmd3.Parameters.AddWithValue("sum", textBox4.Text);

            cmd3.Parameters.AddWithValue("id", textBox1.Text);

            conn.Open();

            cmd3.ExecuteNonQuery();

            conn.Close();

            bind_data();

        }


        private void button4_Click(object sender, EventArgs e)

        {

            SqlCommand cmd4 = new SqlCommand("Delete from Table1 where id=@id", conn);

            cmd4.Parameters.AddWithValue("id", textBox1.Text);

            conn.Open();

            cmd4.ExecuteNonQuery();

            conn.Close();

            bind_data();

        }


        private void button5_Click(object sender, EventArgs e)

        {

            SqlCommand cmd1 = new SqlCommand("Select id,fname As firstname,lname As Lastname,sum from Table1 where fname Like @firstname+'%'", conn);

            cmd1.Parameters.AddWithValue("firstname", textBox5.Text);

            SqlDataAdapter da = new SqlDataAdapter();

            da.SelectCommand = cmd1;

            DataTable dt = new DataTable();

            dt.Clear();

            da.Fill(dt);

            dataGridView1.DataSource = dt;

            dataGridView1.ColumnHeadersDefaultCellStyle.Font = new Font("Tahoma", 12, FontStyle.Bold);

            dataGridView1.DefaultCellStyle.Font = new Font("arial", 12);

        }


        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)

        {

            Bitmap imagebmp = new Bitmap(dataGridView1.Width, dataGridView1.Height);

            dataGridView1.DrawToBitmap(imagebmp, new Rectangle(0, 0, dataGridView1.Width, dataGridView1.Height));

            e.Graphics.DrawImage(imagebmp, 120, 20);

        }


        private void button6_Click(object sender, EventArgs e)

        {

            printPreviewDialog1.Document = printDocument1;

            printPreviewDialog1.PrintPreviewControl.Zoom = 1;

            printPreviewDialog1.ShowDialog();

        }

    }

}

Step by step learn (HTML,PHP and mysql database) with login and logout page with session in PHP

Step by step learn (HTML,PHP and mysql database) with login and logout page with session in PHP Contents: Create a new folder website 00:00 Save as a webpage in folder website login.php 00:29 HTML !DOCTYPE Declaration is an "information" to the browser about what document type to expect. 01:04 The html tag represents the root of an HTML document,and close by 01:13 The header element represents a container for introductory content or a set of navigational links. 01:18 meta charset="UTF-8" 01:23 you are telling your browser to use the UTF-8 character encoding, which is a method of converting your typed characters into machine-readable code. The title tag defines the title of the document 01:39 body contains all the contents of an HTML document. 02:06 The div tag defines a division or a section in an HTML document. 02:56 The h1 tag is used to define HTML heading. 03:13 Add styles to Div "aa" 03:43 Make div in the Center 05:13 Make the text in the center 05:13 The form tag is used to create an HTML form for user input. 06:25 The br tag inserts a single line break.08:04 Add a short hint that describes the expected value of an input field 09:37 Make input fields must be filled out before submitting the form 10:28 OPen XAMPP to create mysql database 11:14 Create database in phpmyadmin 11:59 Create table 12:34 Insert User 13:50 Connect php with database 14:24 Check connection 15:44 Add code php in login page 16:54 Call connect_database file by require 17:14 Start Session 17:41 check if the input username is filled or not null. 17:54 Removes backslashes 18:21 Escapes a string for use in SQL Statements 31:37 check if username exists in mysql database or no 20:05 mysqli_num_rows Returns the number of rows in a recordest 22:03 Store Session Username 22:43 Redirect to index.php Page 23:07 Error message 23:36 Check if session username exists 26:27 Create index page 27:46 Add hyperlink 29:39 Create logout page with destroy or remove session username 29:53 #programming_for_everybody Tags: How to connect HTML register form to MySQL database with PHP Login PHP Admin and user login in PHP Administrator login php Registration form in PHP code with validation PHP admin login




Visual Basic.net: how to calculate third column in a datagridview as product of two other columns

 

Public Class Form8

    Private Sub Form8_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim table As New DataTable("table")

        table.Columns.Add("ID", Type.GetType("System.Int32"))

        table.Columns.Add("Name", Type.GetType("System.String"))

        table.Columns.Add("Arabic", Type.GetType("System.Double"))

        table.Columns.Add("English", Type.GetType("System.Double"))

        table.Columns.Add("Sum", Type.GetType("System.Double"))

       DataGridView1.DataSource = table

    End Sub

    Private Sub DataGridView1_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit

        For i As Integer = 0 To DataGridView1.Rows.Count - 1

            Dim a1 As Double = DataGridView1.Rows(i).Cells(2).Value

            Dim b1 As Double = DataGridView1.Rows(i).Cells(3).Value

            Dim c1 As Double = a1 + b1

            DataGridView1.Rows(i).Cells(4).Value = c1

        Next

    End Sub

    Private Sub DataGridView1_DefaultValuesNeeded(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) Handles DataGridView1.DefaultValuesNeeded

        e.Row.Cells("Arabic").Value = "0"

        e.Row.Cells("English").Value = "0"

        e.Row.Cells("Sum").Value = "0"

    End Sub