Blog

Update Command in VB.NET

Posted by Rohatash Kumar Blogs | Visual Basic 2010 Aug 17, 2011
Here we will see how to use update command in VB.NET.

Update command

 

The update command is used to update the existing record from database has the below command:

update table1 set Firstname='rohatash', Lastname='kumar' where City='mumbai' and Id='1'

 

For example

 

Imports System.Data.SqlClient

Module Module1

    Sub Main()

        Dim str As String = "Data Source=.;uid=sa;pwd=Password$2;database=master"

        Dim con As New SqlConnection(str)

        Try

            con.Open()

            Dim com As New SqlCommand("update table1 set Firstname='rohatash', Lastname='kumar' where City='mumbai' and Id='1' ", con)

            Console.WriteLine("Number of row in table:=" & com.ExecuteScalar())

            com.ExecuteNonQuery()

            Console.WriteLine("update has been completed")

            con.Close()

        Catch ex As Exception

            Console.WriteLine("can not update record")

        End Try

    End Sub

End Module

post comment
     

nice blog.....

Posted by Vinit Kumar Sep 21, 2011
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Join a Chapter