CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2000
    Location
    Charlotte, North Carolina
    Posts
    3

    Passing a string to a table

    OK, this is probably a rookie question...but then again I am a rookie. I have written code that gathers a recordset and reads each field (the recordset consists of the one field) one at a time. What I need to do is to have the data (which is a string) be written to another table, which also only has the one field. I have already defined an str to get the string out of the table it is currently in. I just need to get it written to this other table. ANy help would be greatly appreciated.


  2. #2
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: Passing a string to a table

    Any time you're writing string data types to a table in either Access, or SQL Server (i don't know about oracle) you have to surround the data with single tick marks, like this:

    Dim str as string

    str = "INSERT INTO MyTable (StrField) VALUES ('MyData Goes Here')"
    'and then execute this statement.




    when you are using a variable (like you are) you still have to surround the actual data with single ticks marks, but the difference is, with a variable you want the variable's data, not the variable name to be inserted into the table, so you in your sql statement, you have to stop the quotation and append the variable's value and then append the closing tick mark after that. Like this:

    Dim str as string

    str = "INSERT INTO MyTable (StrField) VALUES ('" & sVariable & "')"
    'and execute this.




    Hope this helps/makes sense,
    John

    John Pirkey
    MCSD
    www.ShallowWaterSystems.com
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

  3. #3
    Join Date
    Feb 2000
    Location
    Charlotte, North Carolina
    Posts
    3

    Re: Passing a string to a table

    John, thanks for the help...it works like a charm!!


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

Featured