Click here to Skip to main content
15,888,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Respect all

I have save image in my sql2000 database successfully. Now i want to copy those data and paste to another table Using vb6. When i try to insert records he display a error massage on image field. How can i insert my all rows in another table?

Please help me.

Thank You
Posted
Comments
AmitGajjar 13-Aug-12 5:33am    
Ohhhh!!! now i come to know MySQL2000 is male :D

1 solution

HTML
hey avi,

 try this....

Start a new project in Visual Basic. Form1 is created by default.
Add a command button to Form1. Add the following code to the Command1 Click event:
   Sub Command1_Click ()
      Dim dbsource As database
      Dim dbdest As database
      ' The following hard-coded database names could be changed to
      ' selections from a text box, list box, or combo box to make the
      ' program more generic:
      Set dbsource = OpenDatabase("c:\vb3\biblio.mdb", True, True)
      Set dbdest = OpenDatabase("c:\vb3\test1.mdb", True, False)
      Print CopyStruct(dbsource, dbdest, "titles", "ctitles", True)
      Print CopyData(dbsource, dbdest, "titles", "ctitles")
      dbsource.Close
      dbdest.Close
   End Sub
						
Add the following code to the General Declarations section of Form1:
   'Place the following Function statement on one, single line:
   Function CopyStruct (from_db As Database, to_db As Database,
      from_nm As String, to_nm As String, create_ind As Integer) As Integer

      On Error GoTo CSErr

      Dim i As Integer
      Dim tbl As New Tabledef    'table object
      Dim fld As Field           'field object
      Dim ind As Index           'index object

      'Search to see if the table exists:
      namesearch:
      For i = 0 To to_db.TableDefs.Count - 1
         If UCase(to_db.TableDefs(i).Name) = UCase(to_nm) Then
            If MsgBox(to_nm + " already exists, delete it?", 4) = YES
            Then
               to_db.TableDefs.Delete to_db.TableDefs(to_nm)
            Else
               to_nm = InputBox("Enter New Table Name:")
               If to_nm = "" Then
                  Exit Function
               Else
                  GoTo namesearch
               End If
            End If
            Exit For
         End If
      Next

      'Strip off owner if necessary:
      If InStr(to_nm, ".") <> 0 Then
         to_nm = Mid(to_nm, InStr(to_nm, ".") + 1, Len(to_nm))
      End If
      tbl.Name = to_nm

      'Create the fields:
      For i = 0 To from_db.TableDefs(from_nm).Fields.Count - 1
         Set fld = New Field
         fld.Name = from_db.TableDefs(from_nm).Fields(i).Name
         fld.Type = from_db.TableDefs(from_nm).Fields(i).Type
         fld.Size = from_db.TableDefs(from_nm).Fields(i).Size
         fld.Attributes = from_db.TableDefs(from_nm).Fields(i).Attributes
         tbl.Fields.Append fld
      Next

      'Create the indexes:
      If create_ind <> False Then
         For i = 0 To from_db.TableDefs(from_nm).Indexes.Count - 1
         Set ind = New Index
         ind.Name = from_db.TableDefs(from_nm).Indexes(i).Name
         ind.Fields = from_db.TableDefs(from_nm).Indexes(i).Fields
         ind.Unique = from_db.TableDefs(from_nm).Indexes(i).Unique
         If gstDataType <> "ODBC" Then
            ind.Primary = from_db.TableDefs(from_nm).Indexes(i).Primary
         End If
         tbl.Indexes.Append ind
         Next
      End If

      'Append the new table:
      to_db.TableDefs.Append tbl

      CopyStruct = True
      GoTo CSEnd

      CSErr:
      CopyStruct = False
      Resume CSEnd

      CSEnd:
   End Function

   'Place the following Function statement on one, single line:
   Function CopyData (from_db As Database, to_db As Database,
      from_nm As String, to_nm As String) As Integer

      On Error GoTo CopyErr
      Dim ds1 As Dynaset, ds2 As Dynaset
      Dim i As Integer
      Set ds1 = from_db.CreateDynaset(from_nm)
      Set ds2 = to_db.CreateDynaset(to_nm)
      While ds1.EOF = False
         ds2.AddNew
         For i = 0 To ds1.Fields.Count - 1
            ds2(i) = ds1(i)
         Next
         ds2.Update
         ds1.MoveNext
      Wend
      CopyData = True
      GoTo CopyEnd
      CopyErr:
      CopyData = False
      Resume CopyEnd
      CopyEnd:
   End Function
						
Start the program or press the F5 key.
You can check to see if the table was copied correctly to the TEST1.MDB database by opening TEST1.MDB with Microsoft Access or with the Data Manager provided with Visual Basic. You can run the Data Manager program from the Window menu in Visual Basic or from the Windows File Manager run DATAMGR.EXE in the Visual Basic directory.
 
Share this answer
 
Comments
wilsotc 26-Feb-21 17:08pm    
This is some of the rarest information on the internet. It doesn't exist on S.O. Haha! Those of use who where programming with vb3 when it was brand new still know these methods. Five stars!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900