Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Create a virtual table for form RecordSource

Create a virtual table for form RecordSource

Scheduled Pinned Locked Moved Database
questiondatabase
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    john john mackey
    wrote on last edited by
    #1

    I am using a SQL statement to fill the contents of a subform's RecordSource:

    Me.sub_NestedSchedule.Form.RecordSource = strMySqlStatement

    How can I create a "virtual table" that has the empty string for all 6 of its fields and force that into my subform's RecordSource? I want to initialize the subform during OnLoad and have the empty string. Thanks, JJM

    M B 2 Replies Last reply
    0
    • J john john mackey

      I am using a SQL statement to fill the contents of a subform's RecordSource:

      Me.sub_NestedSchedule.Form.RecordSource = strMySqlStatement

      How can I create a "virtual table" that has the empty string for all 6 of its fields and force that into my subform's RecordSource? I want to initialize the subform during OnLoad and have the empty string. Thanks, JJM

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Not sure how you are using the sql string but if you query the table with a nonsense where clause you will get back and empty data table.

      Select * from MyTable where IDField = 0

      Select * from MyTable where 1=1

      These will return an empty datatable

      Never underestimate the power of human stupidity RAH

      G J 2 Replies Last reply
      0
      • M Mycroft Holmes

        Not sure how you are using the sql string but if you query the table with a nonsense where clause you will get back and empty data table.

        Select * from MyTable where IDField = 0

        Select * from MyTable where 1=1

        These will return an empty datatable

        Never underestimate the power of human stupidity RAH

        G Offline
        G Offline
        Goutam Patra
        wrote on last edited by
        #3

        Select * from MyTable where 1=1

        I think the previous SQL statement will return all rows in table I think this is what you want to say

        Select * from MyTable where 1=2

        In addition to those solutions we can use

        Select top 0 * from MyTable

        J 1 Reply Last reply
        0
        • G Goutam Patra

          Select * from MyTable where 1=1

          I think the previous SQL statement will return all rows in table I think this is what you want to say

          Select * from MyTable where 1=2

          In addition to those solutions we can use

          Select top 0 * from MyTable

          J Offline
          J Offline
          john john mackey
          wrote on last edited by
          #4

          YES! That's the ticket... To initialize my RecordSource with an empty table that has the EmptyString instead of "#Name?" appearing, here is what I did. I used a table that had a text data field (Label) and has as default value the empty string. I know that this table (tbl_MyHandyTable) will always be present. So I did this:

          strSQL_subform = "SELECT [Lable] AS field1, [Label] AS field2, "
          strSQL_subform = strSQL_subform + "[Label] AS field-N, "
          ...
          strSQL_subform = strSQL_subform + "FROM [tbl_MyHandyTable] "
          strSQL_subform = strSQL_subform + "WHERE 1=2;"

          'initialize the record source with the empty table of EmptyStrings
          Me.RecordSource = strSQL_subform

          Thanks all!

          1 Reply Last reply
          0
          • M Mycroft Holmes

            Not sure how you are using the sql string but if you query the table with a nonsense where clause you will get back and empty data table.

            Select * from MyTable where IDField = 0

            Select * from MyTable where 1=1

            These will return an empty datatable

            Never underestimate the power of human stupidity RAH

            J Offline
            J Offline
            john john mackey
            wrote on last edited by
            #5

            Thanks, i understood what you were getting at and arrived at my solution - following post.

            1 Reply Last reply
            0
            • J john john mackey

              I am using a SQL statement to fill the contents of a subform's RecordSource:

              Me.sub_NestedSchedule.Form.RecordSource = strMySqlStatement

              How can I create a "virtual table" that has the empty string for all 6 of its fields and force that into my subform's RecordSource? I want to initialize the subform during OnLoad and have the empty string. Thanks, JJM

              B Offline
              B Offline
              Bernhard Hiller
              wrote on last edited by
              #6

              The ExecuteReader() function of a command can receive a CommandBehavior parameter. Why not use CommandBehavior.SchemaOnly or CommandBehavior.KeyInfo? E.g.

                      SqlCommand cmd = new SqlCommand("SELECT \* FROM MyTable");
                      SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SchemaOnly);
              
              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups