but!... comming soon!

About Techinforoad.com

Welcome to Techinforoad.com - my website where I will publish various articles, tutorials and how-tos on Microsoft Business Solutions Dynamics NAV, SQL Server, virtualization technology and more.
VB Sample
User Rating: / 0
PoorBest 

This a sample shows how the selected person from AdventureWorks.Person.Contact table is copied into AdventureWorks.Person.ContactTemp table after user inserts a ContactID

insertnow

 

VB .NET
Imports System.Data.SqlClient

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsert.Click
Dim contactID As Integer
contactID = txtContactID.Text

Dim connectionString As String _
= "Data Source =localhost\SqlExpress; Initial Catalog=AdventureWorks; Integrated Security =True"
Dim connection As New SqlConnection(connectionString)

Dim insertStatement As String _
= "INSERT INTO Person.ContactTemp (FirstName, LastName, EmailAddress, Phone) " _
& "SELECT c.FirstName, c.LastName, c.EmailAddress, c.Phone " _
& "FROM Person.Contact c " _
& "WHERE c.ContactID=@ContactID"

Dim param As SqlParameter
param = New SqlParameter("@ContactID", SqlDbType.Int)
param.Value = CInt(txtContactID.Text)

connection.Open()
Dim command As SqlCommand = connection.CreateCommand()
command.CommandText = insertStatement
command.Parameters.Add(param)

Dim nResult As Integer = command.ExecuteNonQuery()

If nResult > 0 Then
txtOutput.Text = "Insert completed" & vbCrLf & nResult & " records inserted"
End If

connection.Close()
command.Dispose()

End Sub
End Class