Programming for Everybody: March 2020

Source Code: how to create Multiplication Table with for... next Loop in Visual Basic.Net

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

        Dim n, result, tm As Integer


        Dim str As String



        tm = TextBox2.Text


        Me.TextBox1.Text = ""



        For n = 1 To 12

            str = tm & "x" & n & "="



            result = tm * n


            Me.TextBox1.Text = TextBox1.Text & str & result & vbCrLf



        Next



    End Sub

How to update All Data From Datagridview To Database In Vb.net [ with source code ]





Imports System.Data
Imports System.Data.SqlClient

Public Class Form2

    Dim conn1 As New SqlConnection("data source=.;initial catalog=users;integrated security=true")


    Private Sub Form2_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("Country", Type.GetType("System.String"))
        table.Columns.Add("id_group", Type.GetType("System.Int32"))


        Dim cmd As New SqlCommand("", conn1)

        With cmd

            .Connection = conn1

            .CommandText = "select id,name,country,id_group from table2 where id_group=" & Label1.Text & ""


        End With

        Dim da As New SqlDataAdapter
        da.SelectCommand = cmd

        Dim dt As New DataTable
        dt.Clear()
        da.Fill(dt)
        DataGridView1.DataSource = dt

        DataGridView1.AllowUserToAddRows = False

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

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


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


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








    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        For i As Integer = 0 To DataGridView1.Rows.Count - 1

            Dim cmd4 As New SqlCommand("", conn1)

            cmd4.CommandText = "update table2 set name='" & DataGridView1.Rows(i).Cells(1).Value & "',country='" & DataGridView1.Rows(i).Cells(2).Value & "' where id=" & DataGridView1.Rows(i).Cells(0).Value & ""

            conn1.Open()
            cmd4.ExecuteNonQuery()
            conn1.Close()


        Next
        MessageBox.Show("Rows updated successfully")


    End Sub

    
   

   
   
    Private Sub DataGridView1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DataGridView1.KeyDown
        If e.KeyCode = Keys.Right Then


            For i As Integer = 0 To DataGridView1.Rows.Count - 1
                Dim constring5 As String = "Data Source=.;Initial Catalog=users;Integrated Security = true"
                Dim Query5 As String = "select id,name,country,id_group from table2 where id= '" & DataGridView1.Rows(i).Cells(0).Value & "'"
                Dim cn5 As SqlConnection = New SqlConnection(constring5)
                Dim cmd5 As SqlCommand = New SqlCommand(Query5, cn5)


                cn5.Open()

                If True Then

                    Using read5 As SqlDataReader = cmd5.ExecuteReader()

                        While read5.Read()
                            DataGridView1.Rows(i).Cells(1).Value = (read5("Name"))
                            DataGridView1.Rows(i).Cells(2).Value = (read5("Country"))



                        End While
                    End Using
                End If



                cn5.Close()





            Next
        End If
    End Sub
End Class

روابط قناة information Channel 2015





-          How to Create Setup exe program in Visual Studio- VB.Net & C#
-          فيديو 53 ثانية لحل مشكلة عدم عمل الملفات والبرامج باللغة العربية في ويندوز 10

-      cannot open sql server 
-       How to Draw 3D Cube
-       Setup SQl Server 2008