Programming for Everybody

Delete Rows from DataGridView and Database using VB Net- With source code

In this Video I will explain, how to delete  Rows from DataGridView and Database in Windows (WinForms) Application using VB.Net.
When the Delete Button is clicked, a Confirmation MessageBox will be displayed and if the User clicks Yes button the Row will be deleted from DataGridView and Database using VB.Net.


: Source Code

Imports System.Data

Imports System.Data.SqlClient



Public Class Form1

    Private Const conn1 As String = "data source=.;initial catalog=users;integrated security=true"



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

    Private Sub bindgridview()

        DataGridView1.AllowUserToAddRows = False

        DataGridView1.Columns.Clear()



        Dim id As DataGridViewColumn = New DataGridViewTextBoxColumn


        id.Name = "id"

        id.HeaderText = "ID"

        id.DataPropertyName = "id"

        id.Width = 70

        DataGridView1.Columns.Insert(0, id)


        Dim name As DataGridViewColumn = New DataGridViewTextBoxColumn


        name.Name = "name"

        name.HeaderText = "name"

        name.DataPropertyName = "name"

        name.Width = 100

        DataGridView1.Columns.Insert(1, name)


        Dim country As DataGridViewColumn = New DataGridViewTextBoxColumn


        country.Name = "country"

        country.HeaderText = "country"

        country.DataPropertyName = "country"

        country.Width = 100

        DataGridView1.Columns.Insert(2, country)


        DataGridView1.DataSource = Nothing

        Using con As SqlConnection = New SqlConnection(conn1)


            Using cmd As SqlCommand = New SqlCommand("Select id,name,country from table1", con)


                cmd.CommandType = CommandType.Text


                Using sda As SqlDataAdapter = New SqlDataAdapter(cmd)



                    Using dt As DataTable = New DataTable



                        sda.Fill(dt)

                        DataGridView1.DataSource = dt



                    End Using



                End Using


            End Using

        End Using


        Dim buttoncolumn As DataGridViewButtonColumn = New DataGridViewButtonColumn


        buttoncolumn.HeaderText = ""

        buttoncolumn.Width = 100

        buttoncolumn.Name = "buttoncolumn"

        buttoncolumn.Text = "Delete"

        buttoncolumn.UseColumnTextForButtonValue = True


        DataGridView1.Columns.Insert(3, buttoncolumn)






    End Sub

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

        If e.ColumnIndex = 3 Then


            Dim row1 As DataGridViewRow = DataGridView1.Rows(e.RowIndex)


            If MessageBox.Show(String.Format("Do you want to delete id:{0}", row1.Cells("id").Value), "confirmation", MessageBoxButtons.OKCancel) = DialogResult.OK Then


                Using con As New SqlConnection(conn1)

                    Using cmd As New SqlCommand("delete from table1 where id=@id", con)


                        cmd.CommandType = CommandType.Text

                        cmd.Parameters.AddWithValue("@id", row1.Cells("id").Value)

                        con.Open()

                        cmd.ExecuteNonQuery()

                        con.Close()

                        Me.bindgridview()





                    End Using




                End Using





            End If




        End If






    End Sub
End Class


كيفية تحويل قاعدة بيانات Access إلى SQL Server بدون برامج مع الربط بينهما

طريقة بسيطة وسهلة لتحويل قاعدة بيانات اكسيس إلى SQL Server بدون برامج مع وجود مفاجأة بالفيديو .



حل مشكلة عدم عمل الملفات والبرامج باللغة العربية في ويندوز 10

في مشكلة بتواجهنا وهي عدم عمل الملفات والبرامج باللغة العربية حتى لو انت ضايف اللغة العربية الفيديو الصغير ده لحل تلك المشكلة بشكل بسيط وسهل .



دمج البيانات الموجودة بقاعدة بيانات أكسيس مع ملف وورد MS Word (دمج المراسلات Mail Merge)

- خطوات دمج المراسلات بين access و word : 






1)  نختار قائمة External Data
2) Word Merge
3) سيظهر مربع حواري به اختيارين 
  • Link your data to an Existing Microsoft Word وده معناه الربط مع ملف موجود
  •   Create A new Document and then link data to it وده معناه إنشاء ملف جديد والربط به.     
4) هنختار الملف المراد الربط به المنشأ من قبل ثم ننتظر إلى أن يفتح ملف ال Word.

5)   نكمل خطوات دمج المراسلات بإختيار : Next write Your letter

6)  نختار More Items لإضافة البيانات من حقول قاعدة البيانات أم كل قيمة في ملف ال Word.
7) نختار preview your letters  لعمل معاينة للدمج. 

8 ) نختار Next:  complete the merge 

9 )  عايزين التحكم في  عدد السجلات المعروضة من قاعدة البيانات  هنختار 
Edit individual letters

هيظهر ثلاث اختيارات : 


  1. all كل سجلات قاعدة البيانات.
  2. Current record   السجل الحالي.
  3.  From ... To من السجل كذا ..... للسجل رقم كذا من قاعدة البيانات.











Install wordpress on localhost Xampp 2020


Steps: 

Step1:download Xampp

Step2:Install Xampp

Step3:open control panel Xampp

Step4:Solve problem port 80

Step5:download wordpress

Step6:extract and  copy files

Step7:Paste files in C:\xampp\htdocs\website1

step8 : choose language 

step 9 : create database 

step 10 : input data server 

step 11 : Congratulations







How to take full page screen capture of a web page

The simplest way to take a full page screenshot of your current browser window.