تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
insert .. select
#4
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()

RolleyesRolleyesRolleyes
{‏‏ يَرْفَعِ اللَّهُ الَّذِينَ آمَنُوا مِنكُمْ وَالَّذِينَ أُوتُوا الْعِلْمَ دَرَجَاتٍ‏ }

 " Mohamed M. Bedair     -     " Abu Anas
Genius Live , Egypt
الرد }}}
تم الشكر بواسطة: Sajad


الردود في هذا الموضوع
insert .. select - بواسطة atefkhalf2004 - 19-12-13, 04:43 PM
RE: insert .. select - بواسطة Sajad - 19-12-13, 11:35 PM
RE: insert .. select - بواسطة amgadtamer - 20-12-13, 12:08 PM
RE: insert .. select - بواسطة Genius Live - 21-12-13, 05:55 AM
RE: insert .. select - بواسطة atefkhalf2004 - 21-12-13, 02:52 PM
RE: insert .. select - بواسطة Genius Live - 21-12-13, 03:29 PM
RE: insert .. select - بواسطة atefkhalf2004 - 23-12-13, 02:06 PM


التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم