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. view

view

Scheduled Pinned Locked Moved Database
databasehelpquestion
4 Posts 2 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.
  • M Offline
    M Offline
    magnifique
    wrote on last edited by
    #1

    i am working on a project to automatically generate view if the user select certain number of tables. my problem is how can i save the query generated as a view

    F 1 Reply Last reply
    0
    • M magnifique

      i am working on a project to automatically generate view if the user select certain number of tables. my problem is how can i save the query generated as a view

      F Offline
      F Offline
      Frank Kerrigan
      wrote on last edited by
      #2

      create an execute non query and create a view. CREATE VIEW dbo.vw_myview AS SELECT * from mytable

      M 1 Reply Last reply
      0
      • F Frank Kerrigan

        create an execute non query and create a view. CREATE VIEW dbo.vw_myview AS SELECT * from mytable

        M Offline
        M Offline
        magnifique
        wrote on last edited by
        #3

        i understand your anwser but my question is this the query is autogenerated in a form of string in a text box so how can i pass the string query and save it as a view using sqldmo

        F 1 Reply Last reply
        0
        • M magnifique

          i understand your anwser but my question is this the query is autogenerated in a form of string in a text box so how can i pass the string query and save it as a view using sqldmo

          F Offline
          F Offline
          Frank Kerrigan
          wrote on last edited by
          #4

          Try something like this You will have to fill in the blanks for connections string etc.. Before some pipes up with "injection attacks security risks etc..." This is a very basic code to give an idea of how it could work. ========================= string MySQL = TextBox1.Text; // SQL in the view select * from table string MyViewName = TextBox2.Text; // The view name on DB SQLstring = "CREATE VIEW " + MyViewName + " AS " + MySQL SqlConnection myConnection = new SqlConnection(strConnectSQL); SqlCommand myCommand = new SqlCommand( SQLstring, myConnection ); try { myConnection.Open(); myCommand.ExecuteScalar(); myConnection.Close(); } catch { myConnection.Close(); }

          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