Results 1 to 7 of 7

Thread: [RESOLVED] insert memo field msaccess vb.net

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    86

    Resolved [RESOLVED] insert memo field msaccess vb.net

    We are trying to read from an MS access database table and write into multiple tables. Both source and destination have memo fields that store tag related data with special characters. We are trying to write a vb.net program using datareader and have not been able to insert the read data into the destination column successfully.
    Is there any way to get around this issue. We are at our wits end at this point.

    Thanks!!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: insert memo field msaccess vb.net

    To give us an idea of what the issue might be, how about you show us what you're doing at the moment? There's not much point suggesting something that you may already be doing.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    86

    Re: insert memo field msaccess vb.net

    Iam trying to copy the contents of fields from one table in a access database to other fields in another table of a second access database.
    Iam pasting the code that iam working on.iam not able to copy the contents of the memo fields into the destination database.in this col6 and col7 are the memo fields .

    Dim cn As OleDbConnection
    Dim cn_dest As OleDbConnection
    Dim cmd As OleDbCommand
    Dim cmdold As OleDbCommand
    Dim dr As OleDbDataReader
    Dim icount As Integer
    Dim str As String

    Dim col3 As Integer
    Dim col4 As String
    Dim col5 As String
    Dim col6 As String
    Dim col7 As String

    Try
    cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Amoushmi\CMS\Old_db\cMS.mdb;")
    'provider to be used when working with access database
    cn.Open()
    cmdold = New OleDbCommand("select * from WebContent", cn)
    dr = cmdold.ExecuteReader
    cn_dest = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Amoushmi\CMS\New_cms\DB\aCMS.mdb;")
    cn_dest.Open()

    Dim AccessCommand As New System.Data.OleDb.OleDbCommand("DELETE * FROM [tblContent_languages]", cn_dest)
    AccessCommand.ExecuteNonQuery()

    While dr.Read()


    col3 = CInt(dr(1))
    col4 = CStr(dr(2))
    col5 = CStr(dr(4))
    col6 = CStr(dr(5))
    ' col7 = CStr(dr(21))

    str = "insert into tblContent_languages(templateid,contentName,contentTitle,contentBody) values (" & col3 & ",'" & col4 & "','" & col5 & "','" & col6 & "')"
    'string stores the command and CInt is used to convert number to string
    cmd = New OleDbCommand(str, cn_dest)

    icount = cmd.ExecuteNonQuery
    End While
    Catch
    End Try
    dr.Close()
    cn.Close()
    cn_dest.Close()

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: insert memo field msaccess vb.net

    You should not be using string concatenation to build SQL statements at the best of times, but if you have large memo fields then you're going to break the SQL statement character limit pretty quickly.
    VB Code:
    1. str = "INSERT INTO tblContent_languages (templateid, contentName, contentTitle, contentBody) VALUES (@TemplateID, @ContentName, @ContentTitle, @ContentBody)"
    2. cmd = New OleDbCommand(str, cn_dest)
    3. cmd.Parameters.AddWithValue("@TemplateID", col3)
    4. cmd.Parameters.AddWithValue("@ContentName", col4)
    5. cmd.Parameters.AddWithValue("@ContentTitle", col5)
    6. cmd.Parameters.AddWithValue("@ContentBody", col6)
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    86

    Re: insert memo field msaccess vb.net

    That worked! Thanks a bunch!

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: insert memo field msaccess vb.net

    Cool. Don't forget to resolve your thread from the Thread Tools menu.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: insert memo field msaccess vb.net

    Fyi, Aprox. 64,000 characters for an Access sql string limit.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width