db open

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • OuTCasT
    Contributor
    • Jan 2008
    • 374

    #1

    db open

    Hi all,
    ive got the payroll solution that i am busy with, now when it is first run the user creates a company which is a sql database that is saved in the application.sta rtupPath. every company will have its own db
    Now i have created the New company form, and it creates the company/db. and the main form is shown.

    what my problem is. say there are 2 companies created. i have displayed them in a listbox so u can choose which company you want to use.
    i have used the stored proc sp_databases to display the databases/companies that are present in sqlExpress.

    all the databases will have the same tables and names etc, just the database name will differ.

    i want to be able to select a database in the listbox and when i click open thats the database that i will be using in the application, so if i closed the application and i selected another database from the listbox and clicked open then it would use the selected database.

    is that possible ?
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Originally posted by OuTCasT
    Hi all,
    ive got the payroll solution that i am busy with, now when it is first run the user creates a company which is a sql database that is saved in the application.sta rtupPath. every company will have its own db
    Now i have created the New company form, and it creates the company/db. and the main form is shown.

    what my problem is. say there are 2 companies created. i have displayed them in a listbox so u can choose which company you want to use.
    i have used the stored proc sp_databases to display the databases/companies that are present in sqlExpress.

    all the databases will have the same tables and names etc, just the database name will differ.

    i want to be able to select a database in the listbox and when i click open thats the database that i will be using in the application, so if i closed the application and i selected another database from the listbox and clicked open then it would use the selected database.

    is that possible ?

    Yes.

    First, you have to place what the user chooses into a variable. If this is a browser based apps, you have to keep the value of this variable visible on all pages. During your creation of connection object or data object you have to build it dynamically to connect to that database.

    So your query would look like:

    Code:
    t-sqlvar = 'select column from ' + dbvar + '..table'
    -- CK

    Comment

    • OuTCasT
      Contributor
      • Jan 2008
      • 374

      #3
      Originally posted by ck9663
      Yes.

      First, you have to place what the user chooses into a variable. If this is a browser based apps, you have to keep the value of this variable visible on all pages. During your creation of connection object or data object you have to build it dynamically to connect to that database.

      So your query would look like:

      Code:
      t-sqlvar = 'select column from ' + dbvar + '..table'
      -- CK
      Hi CK

      What i did was put in a module to the project to carry the value that i chose from the listbox to the next page.
      then in the connectionstrin g i used

      [CODE=vb]Server=(local); Data Source=.\sqlexp ress;Initial Catalog='" & txtDatabase.Tex t & "';Integrat ed Security=True"[/CODE]

      then all the information from the commands that i built would be called from the database name that was in the textbox.

      Is that the best way to do it ?

      Comment

      • ck9663
        Recognized Expert Specialist
        • Jun 2007
        • 2878

        #4
        Yes and No ;)

        I've used some of tools that revert back the db connection to my default db. If you have created a lot of query already you can use your technique without changing anything. So, yes, that would be fine.If you don't have any other db on the server with the same object name, you should be fine.

        If you just started, try to specify which database you are running your t-sql from by placing the db name on the object, so No, to make sure, just place the dbname.

        -- CK

        Comment

        • OuTCasT
          Contributor
          • Jan 2008
          • 374

          #5
          Originally posted by ck9663
          Yes and No ;)

          I've used some of tools that revert back the db connection to my default db. If you have created a lot of query already you can use your technique without changing anything. So, yes, that would be fine.If you don't have any other db on the server with the same object name, you should be fine.

          If you just started, try to specify which database you are running your t-sql from by placing the db name on the object, so No, to make sure, just place the dbname.

          -- CK
          When the user chooses to create a company/database i place and if statement
          If exists then notify the user and exit the sub so there is not chances of duplication.
          and i have a delete Company button which deletes the selected company/database from the listbox.selecte ditem but i want to display a msgbox saying u are now about to delete the selected company.
          ive used msgbox("blablab la", msgboxstyle.yes no)
          if msgbox.result = yes then
          delete company
          else
          if msgbox.result = no then
          exit sub
          end if
          end if
          but that doesnt seem to work

          how do i process the choices made in the msgbox, i knw its a stupid question.

          Comment

          • OuTCasT
            Contributor
            • Jan 2008
            • 374

            #6
            Originally posted by OuTCasT
            When the user chooses to create a company/database i place and if statement
            If exists then notify the user and exit the sub so there is not chances of duplication.
            and i have a delete Company button which deletes the selected company/database from the listbox.selecte ditem but i want to display a msgbox saying u are now about to delete the selected company.
            ive used msgbox("blablab la", msgboxstyle.yes no)
            if msgbox.result = yes then
            delete company
            else
            if msgbox.result = no then
            exit sub
            end if
            end if
            but that doesnt seem to work

            how do i process the choices made in the msgbox, i knw its a stupid question.
            i got it no worries

            [CODE=vb]Try
            Select Case MsgBox("Delete Selected Company", MsgBoxStyle.Yes No)
            Case MsgBoxResult.Ye s
            sqlCon.Open()
            sqlDeleteCompan ycommand.Execut eNonQuery()
            lbExistingCompa nies.Items.Remo ve(lbExistingCo mpanies.Selecte dItem)
            sqlCon.Close()
            Case MsgBoxResult.No
            Exit Sub
            End Select
            Catch ex As Exception
            MsgBox(ex.Messa ge)
            End Try[/CODE]

            Comment

            Working...