21-12-13, 05:55 AM
This code will do the job



كود :
Dim A, B, C, D
Dim CMD As New SqlCommand
Dim con1 As New SqlConnection(ConnectionString)
If con1.State = ConnectionState.Open Then con1.Close()
Dim DBC As New SqlCommand
Dim DBDR As SqlDataReader
With DBC
.Connection = con1
.CommandText = "SELECT " & _
"table1.ID, " & _
"table1.field1, " & _
"table1.field2, " & _
"table1.field3 " & _
"FROM table1 " & _
"WHERE (table1.ID =2) "
End With
con1.Open()
DBDR = DBC.ExecuteReader
DBDR.Read()
If DBDR.HasRows Then
A = (DBDR.Item("ID"))
B = (DBDR.Item("field1"))
C = (DBDR.Item("field2"))
D = (DBDR.Item("field3"))
con1.Close()
End If
Dim INS As String = "INSERT INTO [table2] " & _
"([ID] " & _
",[field1] " & _
",[field2] " & _
",[field3] ) " & _
"VALUES (" & _
"" & A & "" & _
",'" & B & "' " & _
",'" & C & "' " & _
",'" & D & "' ") "
Dim con2 As New SqlConnection(ConnectionString)
If con2.State = ConnectionState.Open Then con2.Close()
CMD= New SqlCommand(INS, con2)
GETID()
con2.Open()
CMD.ExecuteNonQuery()
con2.Close()


{ يَرْفَعِ اللَّهُ الَّذِينَ آمَنُوا مِنكُمْ وَالَّذِينَ أُوتُوا الْعِلْمَ دَرَجَاتٍ }
" Mohamed M. Bedair - " Abu Anas
Genius Live , Egypt

