VB.NET Update Sql Server Database Data

VB.NET - How To Update SqlServer DataBase Data Using Visual Basic .Net

                                                                                                                         

In This VB.NET Tutorial We Will See How To Update Microsoft SQL DataBase Records Using Visual Basic .NET Programming Language.


Project Source Code:


Imports System.Data.SqlClient

Public Class VBNET_SQL_UPDATE

    Dim connection As New SqlConnection("Server= SAMSNG-PC; Database = TestDB; Integrated Security = true")

    Private Sub BTN_UPDATE_Click(sender As Object, e As EventArgs) Handles BTN_UPDATE.Click

        If TextBoxID.Text = "" Then
            MessageBox.Show("Empty Id")

        Else

            Dim command As New SqlCommand("UPDATE Users SET Fname = @fn ,Lname = @ln ,age = @age WHERE Id = @id", connection)

            command.Parameters.Add("@fn", SqlDbType.VarChar).Value = TextBoxFN.Text
            command.Parameters.Add("@ln", SqlDbType.VarChar).Value = TextBoxLN.Text
            command.Parameters.Add("@age", SqlDbType.Int).Value = TextBoxAGE.Text
            command.Parameters.Add("@id", SqlDbType.Int).Value = TextBoxID.Text

            connection.Open()

            If command.ExecuteNonQuery() = 1 Then
                MessageBox.Show("Data Updated")

            Else
                MessageBox.Show("Data Not Updated")
            End If

            connection.Close()

        End If

        

    End Sub
End Class


///////////////OUTPUT:

vb.net update sql database record







Share this

Related Posts

Previous
Next Post »