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

Wednesday, 25 March 2009 12:01 by scngan

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()

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   Technical Stuff
Actions:   | E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed
Comments are closed