How to edit/update data to database using VB.NET

March 25, 2009 at 12:01 PM

How to edit/update data to database using VB.NET ? Below will be a simple code that can help you.

' import the class library
Imports System.Data.SqlClient

'Declare the connection string
Dim strConn As String = "Data Source=.\SQLExpress;integrated security=true;attachdbfilename=|DataDirectory|\StudentDB.mdf;user instance=true;"
'declare the connection
Dim myconn As New SqlConnection(strConn)

Dim updatequery As String = "UPDATE <<TABLE>> SET company=@company,address=@address "
Dim update As New SqlCommand(updatequery, myconn)
With update.Parameters
    .Add(New SqlParameter("@company", txtncompany.Text.ToString.Trim))
    .Add(New SqlParameter("@address", txtaddress.Text.ToString.Trim))
End With
myconn.Open()
renew.ExecuteNonQuery()
myconn.Close()

Posted in: Technical Stuff

Tags: