Z
Zaur Bahramov
Hi!
I'm trying to insert some data into SQL server using ADO. I've created a
sample application that tries to copy a row from Person.Contact to
Person.ContactTemp basing on a parameter (AdventureWorks database).
Something like this:
Imports Microsoft.SqlServer
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 = CInt(txtContactID.Text)
Dim connectionString As String _
= "Data Source =localhost\SqlExpress; Initial Catalog=AdventureWorks;
Integrated Security =True"
Dim connection As New SqlClient.SqlConnection(connectionString)
connection.Open()
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.ToString
Dim insert As New SqlClient.SqlCommand(insertStatement, connection)
txtOutput.Text _
= "insertStatement: " & insertStatement & vbCrLf _
& "insert:" & vbTab & insert.ToString & vbCrLf _
& "ContactID: " & contactID.ToString
connection.Close()
End Sub
End Class
But it doesn't work... What is wrong here?
Thanks!
I'm trying to insert some data into SQL server using ADO. I've created a
sample application that tries to copy a row from Person.Contact to
Person.ContactTemp basing on a parameter (AdventureWorks database).
Something like this:
Imports Microsoft.SqlServer
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 = CInt(txtContactID.Text)
Dim connectionString As String _
= "Data Source =localhost\SqlExpress; Initial Catalog=AdventureWorks;
Integrated Security =True"
Dim connection As New SqlClient.SqlConnection(connectionString)
connection.Open()
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.ToString
Dim insert As New SqlClient.SqlCommand(insertStatement, connection)
txtOutput.Text _
= "insertStatement: " & insertStatement & vbCrLf _
& "insert:" & vbTab & insert.ToString & vbCrLf _
& "ContactID: " & contactID.ToString
connection.Close()
End Sub
End Class
But it doesn't work... What is wrong here?
Thanks!