Programming for Everybody: 2025

Programming in ASP.NET - Insert Update Delete in SQL Server in VB.NET with Source code

 



Imports System.Data

Imports System.Data.SqlClient

Imports System.Drawing

Partial Class _Default

    Inherits System.Web.UI.Page

    Dim conn As New SqlConnection("Data Source=.;Initial Catalog=students2;Integrated Security=True")

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim cmd As New SqlCommand("Insert into Table1(firstname,lastname,marks)Values(@firstname,@lastname,@marks)", conn)

        cmd.Parameters.AddWithValue("firstname", TextBox1.Text)

        cmd.Parameters.AddWithValue("lastname", TextBox2.Text)

        cmd.Parameters.AddWithValue("marks", TextBox3.Text)

        conn.Open()

        cmd.ExecuteNonQuery()

        conn.Close()

        result.Text = "Data Inserted Successfully"

        result.BackColor = Color.Green

        result.ForeColor = Color.White

        result.Font.Size = 16

        GridView1.DataBind()

    End Sub


    Private Sub form1_Load(sender As Object, e As EventArgs) Handles form1.Load

        GridView1.DataBind()

    End Sub


    Private Sub GridView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles GridView1.SelectedIndexChanged

        id1.Visible = True

        id1.Text = HttpUtility.HtmlDecode(GridView1.SelectedRow.Cells.Item(0).Text)

        TextBox1.Text = HttpUtility.HtmlDecode(GridView1.SelectedRow.Cells.Item(1).Text)

        TextBox2.Text = HttpUtility.HtmlDecode(GridView1.SelectedRow.Cells.Item(2).Text)

        TextBox3.Text = HttpUtility.HtmlDecode(GridView1.SelectedRow.Cells.Item(3).Text)

    End Sub

    Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

        Dim cmd As New SqlCommand("Update Table1 Set firstname=@firstname,lastname=@lastname,marks=@marks Where id=@id", conn)

        cmd.Parameters.AddWithValue("id", id1.Text)

        cmd.Parameters.AddWithValue("firstname", TextBox1.Text)

        cmd.Parameters.AddWithValue("lastname", TextBox2.Text)

        cmd.Parameters.AddWithValue("marks", TextBox3.Text)

        conn.Open()

        cmd.ExecuteNonQuery()

        conn.Close()

        result.Text = "Data updated Successfully"

        result.BackColor = Color.Orange

        result.ForeColor = Color.White

        result.Font.Size = 16

        GridView1.DataBind()

    End Sub

    Protected Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click

        Dim cmd As New SqlCommand("Delete from Table1 Where id=@id", conn)

        cmd.Parameters.AddWithValue("id", id1.Text)

        conn.Open()

        cmd.ExecuteNonQuery()

        conn.Close()

        result.Text = "Data Deleted Successfully"

        result.BackColor = Color.Brown

        result.ForeColor = Color.White

        result.Font.Size = 16

        GridView1.DataBind()

        id1.Visible = False

        TextBox1.Text = ""

        TextBox2.Text = ""

        TextBox3.Text = ""

    End Sub

End Class


programming in C# : System calculates installments and due dates 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.Windows.Forms;


namespace System_calculate_installments

{

    public partial class Form2 : Form

    {

        public Form2()

        {

            InitializeComponent();

        }

        DataTable dt = new DataTable();

        private void Form2_Load(object sender, EventArgs e)

        {

            dt.Columns.Add("Installment", typeof(string));

            dt.Columns.Add("Value", typeof(double));

            dt.Columns.Add("Due_date", typeof(DateTime));

            dataGridView1.DataSource = dt;

        }


        private void button1_Click(object sender, EventArgs e)

        {

            double price_v, adv_payment, installment_value, n_installments,final_installment;

            price_v = double.Parse(textBox1.Text);

            adv_payment = double.Parse(textBox2.Text);

            installment_value = double.Parse(textBox3.Text);

            n_installments = Math.Ceiling((price_v - adv_payment) / installment_value);

            final_installment = (price_v - adv_payment) % installment_value;

            dataGridView1.DataSource = null;

            dt.Clear();

            dataGridView1.DataSource = dt;

            for (int i = 1; i <= n_installments; i++)

            {

                var date_payment = (DateTime.Today.AddMonths(i)).ToString("MM-dd-yyyy");

                dt.Rows.Add("Installment" + i, textBox3.Text, date_payment);

            }

            if (final_installment != 0)

            {

                int lastrow = dataGridView1.Rows.Count - 1;

                dataGridView1.Rows[lastrow].Cells[1].Value = final_installment;

            }

        }

          

    }

}


📊 Filter RDLC Report Between Two Dates in C# | Step-by-Step Tutorial

 


code in Video:

private void button1_Click(object sender, EventArgs e)

        {

            this.Table_reg3TableAdapter.filterbydate(this.sportsDataSet.Table_reg3,Convert.ToDateTime(d1.Value).ToString(), Convert.ToDateTime(d2.Value).ToString());


            this.reportViewer1.RefreshReport();

        }


C# DataGridView Paging | WinForms Pagination Step-by-Step (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 WindowsFormsApplication2

{

    public partial class Form2 : Form

    {

        public Form2()

        {

            InitializeComponent();

        }

        SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=sports;Integrated Security=true");

        int pagerows;

        private void count_pages()

        {

            SqlCommand cmd = new SqlCommand("Select Count(*) From Table_reg3", conn);

            conn.Open();

            int count1;

            count1 = int.Parse(cmd.ExecuteScalar().ToString());

            pagerows = Convert.ToInt32(Math.Ceiling(count1 / (double)10));

            label3.Text = pagerows.ToString();

        }

        private void load_data()

        {

            int f1 = Convert.ToInt32(label1.Text) * (int)10 - Convert.ToInt32(10 + 1);

            int t1 = Convert.ToInt32(label1.Text) * (int)10;

            SqlCommand cmd2 = new SqlCommand("Select * From(Select Row_Number() Over(Order By id) As rownumber,id,name1,age,sport,points From Table_reg3) tablerow Where rownumber Between " + f1 + "And " + t1 + "", conn);

            SqlDataAdapter da = new SqlDataAdapter(cmd2);

            DataTable dt = new DataTable();

            da.Fill(dt);

            dataGridView1.DataSource = dt;

        }

        private void Form2_Load(object sender, EventArgs e)

        {

            count_pages();

        }


        private void button1_Click(object sender, EventArgs e)

        {

            label1.Text = 1.ToString();

            load_data();

        }


        private void button2_Click(object sender, EventArgs e)

        {

            if(Convert.ToInt32(label1.Text)< pagerows)

            {

                label1.Text = (Convert.ToInt32(label1.Text) + (int)1).ToString();

                load_data();

            }

        }


        private void button3_Click(object sender, EventArgs e)

        {

            if (Convert.ToInt32(label1.Text) > (int)1)

            {

                label1.Text = (Convert.ToInt32(label1.Text) - (int)1).ToString();

                load_data();

            }

        }


        private void button4_Click(object sender, EventArgs e)

        {

            label1.Text = pagerows.ToString();

            load_data();

        }

    }

}




How to display data excel sheet in userform VBA Using navigation buttons




Dim row_num As Integer
 Private Sub CommandButton2_Click()
row_num = Sheet5.range("A2").End(xlUp).Row + 1
Me.idtxt = Sheet5.Cells(row_num, 1)
load_data
End Sub

Private Sub load_data()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Sheet5")
Dim i As Long
For i = 1 To Sheet5.UsedRange.Rows.Count
If idtxt.Text = Sheet5.Cells(i, 1).Value Then
ftxt.Text = Sheet5.Cells(i, 2).Value
ltxt.Text = Sheet5.Cells(i, 3).Value
sporttxt.Text = Sheet5.Cells(i, 4).Value
pointtxt.Text = Sheet5.Cells(i, 5).Value
Exit Sub
Else
ftxt.Text = ""
ltxt.Text = ""
sporttxt.Text = ""
pointtxt.Text = ""
End If
Next i

End Sub

Private Sub CommandButton3_Click()
If row_num < Sheet5.Cells(Rows.Count, 1).End(xlUp).Row Then
row_num = row_num + 1
Me.idtxt = Sheet5.Cells(row_num, 1)
load_data
End If
End Sub

Private Sub CommandButton4_Click()
If row_num > Sheet5.range("A2").End(xlUp).Row + 1 Then
row_num = row_num - 1
Me.idtxt = Sheet5.Cells(row_num, 1)
load_data
Exit Sub

Else
End If
End Sub

Private Sub CommandButton5_Click()
row_num = Sheet5.Cells(Rows.Count, 1).End(xlUp).Row
Me.idtxt = Sheet5.Cells(row_num, 1)
load_data
End Sub

Private Sub UserForm_Click()

End Sub

c# tutorial for beginners: How to connect Microsoft access database to C#

c# tutorial for beginners: Connect access database (connection-insert-update-delete - search in database) with create access database and add images .
Subscribe to @programmingforeverybody
https://www.youtube.com/@programmingcode2025/?sub_confirmation=1
Contents:
Add controls to your form 00:00
Delete last blank row in datagridview 09:26
Browse button 09:42
Create table database 14:21
Add Dataset and relate it with controls 15:37
change columns header text datagridview 20:52
New button 23:16
Format DateTime column in a DataGridView 25:04
Save or update button 26:17
Search button 29:34
Reset button 32:26
Remove button 33:24
Previous button 34:16
Next button 34:48
First button 35:06
Last button 35:25
Close button 35:41

 



Step by step how to Connect SQL server Database with Visual Basic .net with Source code

Public Class Form1

    Private Sub Browse_btn_Click(sender As Object, e As EventArgs) Handles Browse_btn.Click

        OpenFileDialog1.Filter = "Image|*.png;*.jpg;*.bmp"

        If OpenFileDialog1.ShowDialog = DialogResult.OK Then

            pictxt.Text = OpenFileDialog1.FileName

            PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)

        Else

            pictxt.Text = ""

            PictureBox1.Image = Nothing

        End If

    End Sub


    Private Sub pictxt_TextChanged(sender As Object, e As EventArgs) Handles pictxt.TextChanged

        If pictxt.Text = "" Then

            PictureBox1.Image = Nothing

        Else

            PictureBox1.Image = Image.FromFile(pictxt.Text)

        End If

    End Sub


    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        'TODO: This line of code loads data into the 'Students3DataSet.Table1' table. You can move, or remove it, as needed.

        Me.Table1TableAdapter.Fill(Me.Students3DataSet.Table1)

        DataGridView1.Columns(4).DefaultCellStyle.Format = "MM/dd/yyyy"

        DataGridView1.Columns(0).HeaderText = "ID"

        DataGridView1.Columns(1).HeaderText = "Code"

        DataGridView1.Columns(2).HeaderText = "Name"

        DataGridView1.Columns(3).HeaderText = "Phone"

        DataGridView1.Columns(4).HeaderText = "Date"

        DataGridView1.Columns(5).HeaderText = "Grade"

        DataGridView1.Columns(6).HeaderText = "Class"

        DataGridView1.Columns(7).HeaderText = "Picture"

    End Sub


    Private Sub new_btn_Click(sender As Object, e As EventArgs) Handles new_btn.Click

        Dim row = DirectCast(Table1BindingSource.AddNew(), DataRowView)

        row("rdate") = dtp1.Value

    End Sub


    Private Sub save_btn_Click(sender As Object, e As EventArgs) Handles save_btn.Click

        If (String.IsNullOrEmpty(codetxt.Text)) Then

            ErrorProvider1.SetError(codetxt, "Code Is required")

        Else

            ErrorProvider1.SetError(codetxt, String.Empty)

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

                If codetxt.Text = DataGridView1.Rows(i).Cells(1).Value.ToString And idtxt.Text <> DataGridView1.Rows(i).Cells(0).Value.ToString Then

                    MessageBox.Show("Code Exists Before")

                    Return

                Else

                    Table1BindingSource.EndEdit()

                    Table1TableAdapter.Update(Students3DataSet.Table1)

                End If

            Next

            MessageBox.Show("Data Saved Successfully")

        End If

    End Sub


    Private Sub codetxt_TextChanged(sender As Object, e As EventArgs) Handles codetxt.TextChanged

        If (String.IsNullOrEmpty(codetxt.Text)) Then

            ErrorProvider1.SetError(codetxt, "Code Is required")

        Else

            ErrorProvider1.SetError(codetxt, String.Empty)

        End If

    End Sub


    Private Sub delete_btn_Click(sender As Object, e As EventArgs) Handles delete_btn.Click

        Table1BindingSource.RemoveCurrent()

        Table1TableAdapter.Update(Students3DataSet.Table1)

        PictureBox1.Image = Nothing

    End Sub


    Private Sub first_btn_Click(sender As Object, e As EventArgs) Handles first_btn.Click

        Table1BindingSource.MoveFirst()

    End Sub


    Private Sub next_btn_Click(sender As Object, e As EventArgs) Handles next_btn.Click

        Table1BindingSource.MoveNext()

    End Sub


    Private Sub previous_btn_Click(sender As Object, e As EventArgs) Handles previous_btn.Click

        Table1BindingSource.MovePrevious()

    End Sub


    Private Sub last_btn_Click(sender As Object, e As EventArgs) Handles last_btn.Click

        Table1BindingSource.MoveLast()

    End Sub


    Private Sub close_btn_Click(sender As Object, e As EventArgs) Handles close_btn.Click

        Me.Close()

    End Sub


    Private Sub Search_btn_Click(sender As Object, e As EventArgs) Handles Search_btn.Click

        Me.Table1TableAdapter.search(Me.Students3DataSet.Table1, idtxt.Text)

    End Sub


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Me.Table1TableAdapter.Fill(Me.Students3DataSet.Table1)

    End Sub

End Class



 

How to add new column IIF in subform with change colors cells based on its value in MS Access forms

Learn how to add a new column with IIF function in a subform and change cell colors based on values in MS Access forms. Improve your form design skills with this tutorial!Videos Access
Subscribe to Youtube
 
https://www.youtube.com/@programmingcode2025/?sub_confirmation=1


Code copy table from one database to another database in MYSQL Workbench

 In this video, We will learn copy table from one database to another database in MYSQL Workbench

Subscribe to my channel to find everyday new information in programming and computer Science
"Love coding? Don’t miss out! Subscribe for the latest in programming trends and tech innovations!"
https://www.youtube.com/@programmingcode2025/?sub_confirmation=1
#mysql_tutorial
#mysql
#Wokbench
#mysql_workbench



Full course in 3 minutes connect command line with mysql Workbench

 Full course in 3 minutes connect command line with mysql Workbench

Subscribe to my channel to find everyday new information in programming and computer Science "Love coding? Don’t miss out! Subscribe for the latest in programming trends and tech innovations!" https://www.youtube.com/@programmingcode2025/?sub_confirmation=1 #mysql_tutorial #mysql #Wokbench #mysql_workbench


How to fill Combo box by field list in table in forms MS Access database without vba

 How to fill Combo box by field list in table in forms MS Access database without vba



"Love coding? Don’t miss out! Subscribe for the latest in programming trends and tech innovations!" https://www.youtube.com/@programmingcode2025/?sub_confirmation=1 #access #msaccess #vbaaccess #microsoft #microsoftaccess


How to use Microsoft Access - Beginner Tutorial 2025


Learn how to use Microsoft Access with this beginner tutorial. Whether you're new to Access or just need a refresher, this video will guide you through the basics of using this powerful database management tool.

Subscribe to my channel to find everyday new information in programming and Computerr Science Subscribe to @programmingforeverybody
https://www.youtube.com/@programmingforeverybody/?sub_confirmation=1

 


Access database VBA programmer: Create insert update delete and search in another database with code



 Private Sub Command12_Click()

If (Not IsNull(Me.idtxt.Value)) Then

Dim dbs As DAO.Database

Set dbs = OpenDatabase("H:\rr.accdb")

Dim strsql As String

strsql = "Select firstname,lastname,marks,image1 From Table6 " _

& " Where id= " & Me.idtxt.Value & ""

Dim rst As DAO.Recordset

Set rst = dbs.OpenRecordset(strsql)

If rst.EOF Then

Me.Image1.Picture = ""

Me.ftxt.Value = ""

Me.ltxt.Value = ""

Me.mtxt.Value = ""

Else

Me.Image1.Picture = rst.Fields("image1")

Me.ftxt.Value = rst.Fields("firstname")

Me.ltxt.Value = rst.Fields("lastname")

Me.mtxt.Value = rst.Fields("marks")

End If

rst.Close

Else

MsgBox "Please Enter ID"

End If

End Sub


Private Sub Command13_Click()

Dim dbs As DAO.Database

Set dbs = OpenDatabase("H:\rr.accdb")

Dim strsql As String

strsql = "Update Table6 Set firstname='" & Me.ftxt.Value & "', " _

& "lastname = '" & Me.ltxt.Value & "',marks=" & Me.mtxt.Value & "," _

& "image1='" & Me.Image1.Picture & "' Where id= " & Me.idtxt.Value & ""

dbs.Execute (strsql)

MsgBox "Data Updated Successfully"

End Sub


Private Sub Command14_Click()

Dim dbs As DAO.Database

Set dbs = OpenDatabase("H:\rr.accdb")

Dim strsql As String

strsql = "Delete From Table6 Where id= " & Me.idtxt.Value & ""

dbs.Execute (strsql)

Me.Image1.Picture = ""

Me.ftxt.Value = ""

Me.ltxt.Value = ""

Me.mtxt.Value = ""

Me.idtxt.Value = ""

MsgBox "Data Deleted Successfully"

End Sub


Private Sub Command7_Click()

Dim img_of As Office.FileDialog

Dim img_var As Variant

Set img_of = Application.FileDialog(msoFileDialogFilePicker)

img_of.Title = "Please Select image"

img_of.Filters.Clear

img_of.Filters.Add "Images", "*.png; *.jpg"

If img_of.Show = True Then

For Each img_var In img_of.SelectedItems

Me.Image1.Picture = img_var

Next

Else

Me.Image1.Picture = ""

MsgBox "Please Select Image"

End If

End Sub


Private Sub Command8_Click()

Me.Image1.Picture = ""

Me.ftxt.Value = ""

Me.ltxt.Value = ""

Me.mtxt.Value = ""

Me.idtxt.Value = ""

End Sub


Private Sub Command9_Click()

Dim dbs As DAO.Database

Set dbs = OpenDatabase("H:\rr.accdb")

Dim strsql As String

strsql = "Insert Into Table6(firstname,lastname,marks,image1) " _

& " Values('" & Me.ftxt.Value & "','" & Me.ltxt.Value & "'," _

& "" & Me.mtxt.Value & ",'" & Me.Image1.Picture & "')"

dbs.Execute (strsql)

MsgBox "Data Inserted Successfully"

End Sub



ASP.NET C# insert update delete using SQL database and Load data in Gridview (WITH CODE)

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;



using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data.SqlClient;

using System.Configuration;

public partial class _Default : System.Web.UI.Page

{

    public SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["webaspConnectionString"].ConnectionString);

    protected void Page_Load(object sender, EventArgs e)

    {

        GridView1.DataBind();

    }


    protected void Button1_Click(object sender, EventArgs e)

    {

        SqlCommand cmd = new SqlCommand("Insert Into Table1(firstname,lastname,marks)Values(@firstname,@lastname,@marks)", conn);

        cmd.Parameters.AddWithValue("firstname", ftxt.Text.Trim());

        cmd.Parameters.AddWithValue("lastname", ltxt.Text.Trim());

        cmd.Parameters.AddWithValue("marks", mtxt.Text.Trim());

        conn.Open();

        cmd.ExecuteNonQuery();

        conn.Close();

        result_lbl.Visible = true;

        result_lbl.ForeColor = System.Drawing.Color.Green;

        result_lbl.Text = "Data Inserted Successfully";

        GridView1.DataBind();

    }


    protected void Button2_Click(object sender, EventArgs e)

    {

        ftxt.Text = "";

        ltxt.Text = "";

        mtxt.Text = "";

        id_lbl.Text = "";

        result_lbl.Text = "";

    }


    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)

    {

        id_lbl.Text = GridView1.SelectedRow.Cells[0].Text.ToString();

        ftxt.Text = GridView1.SelectedRow.Cells[1].Text.ToString();

        ltxt.Text = GridView1.SelectedRow.Cells[2].Text.ToString();

        mtxt.Text = GridView1.SelectedRow.Cells[3].Text.ToString();

    }


    protected void Button3_Click(object sender, EventArgs e)

    {

        SqlCommand cmd = new SqlCommand("Update Table1 Set firstname=@firstname,lastname=@lastname,marks=@marks Where id=@id", conn);

        cmd.Parameters.AddWithValue("firstname", ftxt.Text.Trim());

        cmd.Parameters.AddWithValue("lastname", ltxt.Text.Trim());

        cmd.Parameters.AddWithValue("marks", mtxt.Text.Trim());

        cmd.Parameters.AddWithValue("id", id_lbl.Text.Trim());

        conn.Open();

        cmd.ExecuteNonQuery();

        conn.Close();

        result_lbl.Visible = true;

        result_lbl.ForeColor = System.Drawing.Color.Green;

        result_lbl.Text = "Data Updated Successfully";

        GridView1.DataBind();

    }


    protected void Button4_Click(object sender, EventArgs e)

    {

        SqlCommand cmd = new SqlCommand("Delete From Table1 Where id=@id", conn);

                cmd.Parameters.AddWithValue("id", id_lbl.Text.Trim());

        conn.Open();

        cmd.ExecuteNonQuery();

        conn.Close();

        result_lbl.Visible = true;

        result_lbl.ForeColor = System.Drawing.Color.Red;

        result_lbl.Text = "Data Deleted Successfully";

        GridView1.DataBind();

        ftxt.Text = "";

        ltxt.Text = "";

        mtxt.Text = "";

        id_lbl.Text = "";

        

    }


VBA code for search ComboBox in userform Microsoft #Excel With Source Code



 Private Sub ComboBox1_Change()

Dim ws As Worksheet

Set ws = ThisWorkbook.Sheets("Sheet1")

Dim i As Integer

For i = 1 To ws.UsedRange.Rows.Count

If Me.ComboBox1.Column(0) = ws.Cells(i, 2).Value Then

Me.id_txt.Text = ws.Cells(i, 1).Value

Me.math_txt.Text = ws.Cells(i, 3).Value

Me.geo_txt.Text = ws.Cells(i, 4).Value

Me.chem_txt.Text = ws.Cells(i, 5).Value

Me.his_txt.Text = ws.Cells(i, 6).Value

Me.com_txt.Text = ws.Cells(i, 7).Value

End If

Next i

End Sub

Private Sub UserForm_Click()

End Sub

Private Sub UserForm_Initialize()

Dim lastrow, i As Integer

lastrow = Sheet1.Cells(Rows.Count, "B").End(xlUp).Row

For i = 2 To lastrow

Dim vs As String

vs = Sheet1.Cells(i, "B")

Me.ComboBox1.AddItem vs

Next i

End Sub

Master Excel VBA: Insert, Update, Delete, and Search with Pictures + Free Source Code! 🚀

 Dim imagefile As String

Private Sub CommandButton1_Click()

imagefile = Application.GetOpenFilename(Title:="Select Image", _

FileFilter:="ImageFiles(*.png;*.Jpeg;*.JpG), *.png;*.Jpeg;*.JpG")

If imagefile = "False" Then

MsgBox "Please Select one Image"

Else

Me.Image1.Picture = LoadPicture(imagefile)

Me.Image1.PictureSizeMode = fmPictureSizeModeStretch


End If

End Sub


Private Sub CommandButton2_Click()

Dim sheet_v As Worksheet

Set sheet_v = ThisWorkbook.Sheets("Sheet1")

Dim last_row As Integer

last_row = sheet_v.Range("A" & Rows.Count).End(xlUp).Row

sheet_v.Range("A" & last_row + 1).Value = Me.code_student.Value

sheet_v.Range("b" & last_row + 1).Value = Me.name_txt.Value

sheet_v.Range("C" & last_row + 1).Value = Me.age_txt.Value

sheet_v.Range("D" & last_row + 1).Value = imagefile

MsgBox "The student inserted Successfully"

End Sub


Private Sub CommandButton3_Click()

Me.code_student.Value = ""

Me.name_txt.Value = ""

Me.age_txt.Value = ""

imagefile = ""

Me.Image1.Picture = LoadPicture(imagefile)

End Sub


Private Sub CommandButton4_Click()

If Me.search_txt.Text = "" Then

MsgBox "Please Enter code student"

Else

Dim sheet_v As Worksheet

Set sheet_v = ThisWorkbook.Sheets("Sheet1")

Dim last_row, i As Integer

last_row = sheet_v.Range("A" & Rows.Count).End(xlUp).Row

For i = 2 To last_row

If Me.search_txt.Text = sheet_v.Cells(i, 1) Then

Me.code_student.Text = sheet_v.Cells(i, 1)

Me.name_txt.Value = sheet_v.Cells(i, 2)

Me.age_txt.Value = sheet_v.Cells(i, 3)

imagefile = sheet_v.Cells(i, 4)

Me.Image1.Picture = LoadPicture(imagefile)

Me.Image1.PictureSizeMode = fmPictureSizeModeStretch

Exit Sub

Else

Me.code_student.Value = ""

Me.name_txt.Value = ""

Me.age_txt.Value = ""

imagefile = ""

Me.Image1.Picture = LoadPicture(imagefile)

End If

Next i

End If

End Sub


Private Sub CommandButton5_Click()


Dim sheet_v As Worksheet

Set sheet_v = ThisWorkbook.Sheets("Sheet1")

Dim last_row, i As Integer

last_row = sheet_v.Range("A" & Rows.Count).End(xlUp).Row

For i = 2 To last_row

If Me.search_txt.Text = sheet_v.Cells(i, 1) Then

 sheet_v.Cells(i, 1) = Me.code_student.Text

 sheet_v.Cells(i, 2) = Me.name_txt.Value

sheet_v.Cells(i, 3) = Me.age_txt.Value

 sheet_v.Cells(i, 4) = imagefile

Me.Image1.Picture = LoadPicture(imagefile)

Me.Image1.PictureSizeMode = fmPictureSizeModeStretch


End If

Next i

End Sub


Private Sub CommandButton6_Click()

Dim sheet_v As Worksheet

Set sheet_v = ThisWorkbook.Sheets("Sheet1")

Dim last_row, i As Integer

last_row = sheet_v.Range("A" & Rows.Count).End(xlUp).Row

For i = 2 To last_row

If Me.search_txt.Text = sheet_v.Cells(i, 1) Then

Rows(i).Delete

End If

Next i

Me.code_student.Value = ""

Me.name_txt.Value = ""

Me.age_txt.Value = ""

imagefile = ""

Me.Image1.Picture = LoadPicture(imagefile)

End Sub


Private Sub UserForm_Click()

End Sub




Microsoft Excel Search| search in all columns Excel Using ComboBox in VBA #Excel userforms

 Dim columnindex_v As Integer

Private Sub populate_combo1()

Dim i, lastcolumn As Integer

lastcolumn = Sheet5.Cells(1, Columns.Count).End(xlToLeft).Column

For i = 1 To lastcolumn

Me.ComboBox1.AddItem Sheet5.Cells(1, i).Value

Next i

End Sub


Private Sub ComboBox1_Change()

getcolumnindex

getcolumnname

populate_combo2

End Sub

Private Sub getcolumnindex()

columnindex_v = WorksheetFunction.Match(Me.ComboBox1.Text, Sheet5.Range("1:1"), 0)

Me.columnindex_txt.Caption = columnindex_v

End Sub

Private Sub getcolumnname()

Me.columnname_txt.Caption = Split(Sheet5.Columns(columnindex_v).EntireColumn.Address(0, 0), ":")(0)

End Sub

Private Sub search_listbox1()

With Me.ListBox1

.Clear

.AddItem "RN"

.List(.ListCount - 1, 1) = "ID"

.List(.ListCount - 1, 2) = "Firstname"

.List(.ListCount - 1, 3) = "Lastname"

.List(.ListCount - 1, 4) = "Sport"

.List(.ListCount - 1, 5) = "Points"

.ColumnCount = 6

Dim lastrow, i As Integer

lastrow = Sheet5.Cells(Rows.Count, Me.columnname_txt.Caption).End(xlUp).Row

For i = 2 To lastrow

If Me.ComboBox2.Text = Sheet5.Cells(i, columnindex_v) Then

.AddItem

.List(.ListCount - 1, 0) = .ListCount - 1

.List(.ListCount - 1, 1) = Sheet5.Cells.Range("A" & i)

.List(.ListCount - 1, 2) = Sheet5.Cells.Range("B" & i)

.List(.ListCount - 1, 3) = Sheet5.Cells.Range("C" & i)

.List(.ListCount - 1, 4) = Sheet5.Cells.Range("D" & i)

.List(.ListCount - 1, 5) = Sheet5.Cells.Range("E" & i)

End If

Next i

End With

End Sub

Private Sub ComboBox2_Change()

search_listbox1

End Sub


Private Sub UserForm_Initialize()

populate_combo1

End Sub

Private Sub populate_combo2()

Me.ComboBox2.Clear

Dim lastrow, i As Integer

lastrow = Sheet5.Cells(Rows.Count, Me.columnname_txt.Caption).End(xlUp).Row

For i = 2 To lastrow

Dim value_str As String

value_str = Sheet5.Cells(i, Me.columnname_txt.Caption)

If WorksheetFunction.CountIf(Sheet5.Range(Me.columnname_txt.Caption & 2, Me.columnname_txt.Caption & i), value_str) = 1 Then

Me.ComboBox2.AddItem value_str

End If

Next i

End Sub




visual Basic.net programmer Registration Form in VB.net



Imports System.IO

Imports System.Data.SqlClient

Public Class Form1

    Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged

        If CheckBox1.Checked = True Then

            password.UseSystemPasswordChar = False

        Else

            password.UseSystemPasswordChar = True

        End If

    End Sub


    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

        OpenFileDialog1.ShowDialog()

        image_path.Text = Path.GetDirectoryName(OpenFileDialog1.FileName) & "\" & Path.GetFileName(OpenFileDialog1.FileName)

        PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)

    End Sub


    Private Sub lastname_KeyDown(sender As Object, e As KeyEventArgs) Handles lastname.KeyDown

        If e.KeyCode = Keys.Enter Then

            username.Text = firstname.Text + lastname.Text

        End If

    End Sub


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        If username.Text = "" Then

            MessageBox.Show("Please enter username")

            Return

        End If

        If m1.Checked = False And f1.Checked = False Then

            MessageBox.Show("Please select gender")

            Return

        End If

        Dim conn As New SqlConnection("Data source=.;initial catalog=register2;integrated security=true")

        If conn.State = ConnectionState.Closed Then

            conn.Open()

        End If

        Dim cmd As New SqlCommand("Select username from table1 where username=@username", conn)

        cmd.Parameters.AddWithValue("username", username.Text)

        Dim myreader As SqlDataReader = cmd.ExecuteReader

        If (myreader.Read()) Then

            MessageBox.Show("Username inserted before")

            conn.Close()

            Return

        Else

            conn.Close()


            Dim cmd2 As New SqlCommand("Insert into table1(firstname,lastname,username,password,phone,date_birth,gender,image1)Values(@firstname,@lastname,@username,@password,@phone,@date_birth,@gender,@image1)", conn)

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

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

            cmd2.Parameters.AddWithValue("username", username.Text)

            cmd2.Parameters.AddWithValue("password", password.Text)

            cmd2.Parameters.AddWithValue("phone", phone.Text)

            cmd2.Parameters.AddWithValue("date_birth", date_birth.Text)



            Dim gender_v As Boolean

            If m1.Checked = True Then

                gender_v = 1

            End If

            If f1.Checked = True Then

                gender_v = 0

            End If


            cmd2.Parameters.AddWithValue("gender", gender_v)

            cmd2.Parameters.AddWithValue("image1", image_path.Text)


            If conn.State = ConnectionState.Closed Then

                conn.Open()

            End If

            cmd2.ExecuteNonQuery()

            conn.Close()

            MessageBox.Show("Data inserted Successfully")

        End If

    End Sub

End Class