Microsoft SQL Server 2005 Express

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Omar Abid

    #1

    Microsoft SQL Server 2005 Express

    Hi,
    I'm Trying to make a program with vb2005express that connect to any
    Microsft SQL data base and show it's table. I'm having some problems
    can anyone help me?
    Omar Abid

  • rowe_newsgroups

    #2
    Re: Microsoft SQL Server 2005 Express

    On Mar 28, 6:41 am, "Omar Abid" <omar.abid2...@ gmail.comwrote:
    Hi,
    I'm Trying to make a program with vb2005express that connect to any
    Microsft SQL data base and show it's table. I'm having some problems
    can anyone help me?
    Omar Abid
    You don't actually say what problems you're having, so I'm going to
    assume you can't get anything to work. So as a demo just start a new
    Windows Application and add something like this to a new form's code:

    ' Typed in the message so watch out!

    ' Add this to the top of the class
    Imports System.Data.Sql Client

    Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
    System.EventArg s) Handles MyBase.Load
    ' This is your connection string from www.connectionstrings.com
    ' Be sure to change the necessary parts before running
    Dim conn As New SqlConnection(" Data
    Source=myServer Address;Initial Catalog=myDataB ase;User
    Id=myUsername;P assword=myPassw ord;")
    Using (conn)
    conn.Open()
    Dim com As SqlCommand = conn.CreateComm and()
    Using (com)
    com.CommandType = CommandType.Tex t
    ' Again change "MyTable" to whatever the table name
    should be
    com.CommandText = "Select * From MyTable"
    Dim da As New SqlDataAdapter( com)
    Using (da)
    Dim dt As New DataTable("MyTa ble")
    Using (dt)
    da.Fill(dt)
    Dim dgv As New DataGridView()
    dgv.Dock = DockStyle.Fill
    dgv.DataSource = dt
    Me.Controls.Add (dgv)
    End Using
    End Using
    End Using
    End Using
    End Sub

    Hope that helps.

    Thanks,

    Seth Rowe

    Comment

    • jkimbler

      #3
      Re: Microsoft SQL Server 2005 Express

      On Mar 28, 5:41 am, "Omar Abid" <omar.abid2...@ gmail.comwrote:
      Hi,
      I'm Trying to make a program with vb2005express that connect to any
      Microsft SQL data base and show it's table. I'm having some problems
      can anyone help me?
      Omar Abid
      Remember that MS SQL 2005 Express has a default state where it does
      not allow connections. You have to enable the transport protocols
      first before you can connect to it.

      -Joe

      Comment

      • Omar Abid

        #4
        Re: Microsoft SQL Server 2005 Express

        On 28 mar, 13:14, "rowe_newsgroup s" <rowe_em...@yah oo.comwrote:
        On Mar 28, 6:41 am, "Omar Abid" <omar.abid2...@ gmail.comwrote:
        >
        Hi,
        I'm Trying to make a program with vb2005express that connect to any
        Microsft SQL data base and show it's table. I'm having some problems
        can anyone help me?
        Omar Abid
        >
        You don't actually say what problems you're having, so I'm going to
        assume you can't get anything to work. So as a demo just start a new
        Windows Application and add something like this to a new form's code:
        >
        ' Typed in the message so watch out!
        >
        ' Add this to the top of the class
        Imports System.Data.Sql Client
        >
        Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
        System.EventArg s) Handles MyBase.Load
        ' This is your connection string fromwww.connect ionstrings.com
        ' Be sure to change the necessary parts before running
        Dim conn As New SqlConnection(" Data
        Source=myServer Address;Initial Catalog=myDataB ase;User
        Id=myUsername;P assword=myPassw ord;")
        Using (conn)
        conn.Open()
        Dim com As SqlCommand = conn.CreateComm and()
        Using (com)
        com.CommandType = CommandType.Tex t
        ' Again change "MyTable" to whatever the table name
        should be
        com.CommandText = "Select * From MyTable"
        Dim da As New SqlDataAdapter( com)
        Using (da)
        Dim dt As New DataTable("MyTa ble")
        Using (dt)
        da.Fill(dt)
        Dim dgv As New DataGridView()
        dgv.Dock = DockStyle.Fill
        dgv.DataSource = dt
        Me.Controls.Add (dgv)
        End Using
        End Using
        End Using
        End Using
        End Sub
        >
        Hope that helps.
        >
        Thanks,
        >
        Seth Rowe
        Ok, this help me a lot but i want to open a data base that i don't
        know the name
        i want that the program browse the tables of the base
        Thanks

        Comment

        • rowe_newsgroups

          #5
          Re: Microsoft SQL Server 2005 Express

          Ok, this help me a lot but i want to open a data base that i don't
          know the name
          i want that the program browse the tables of the base
          Do you know the information for the connection string? If you can
          connect to the database you can just query the schema tables and get a
          list of names.

          Thanks,

          Seth Rowe


          On Mar 29, 8:26 am, "Omar Abid" <omar.abid2...@ gmail.comwrote:
          On 28 mar, 13:14, "rowe_newsgroup s" <rowe_em...@yah oo.comwrote:
          >
          >
          >
          On Mar 28, 6:41 am, "Omar Abid" <omar.abid2...@ gmail.comwrote:
          >
          Hi,
          I'm Trying to make a program with vb2005express that connect to any
          Microsft SQL data base and show it's table. I'm having some problems
          can anyone help me?
          Omar Abid
          >
          You don't actually say what problems you're having, so I'm going to
          assume you can't get anything to work. So as a demo just start a new
          Windows Application and add something like this to a new form's code:
          >
          ' Typed in the message so watch out!
          >
          ' Add this to the top of the class
          Imports System.Data.Sql Client
          >
          Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
          System.EventArg s) Handles MyBase.Load
          ' This is your connection string fromwww.connect ionstrings.com
          ' Be sure to change the necessary parts before running
          Dim conn As New SqlConnection(" Data
          Source=myServer Address;Initial Catalog=myDataB ase;User
          Id=myUsername;P assword=myPassw ord;")
          Using (conn)
          conn.Open()
          Dim com As SqlCommand = conn.CreateComm and()
          Using (com)
          com.CommandType = CommandType.Tex t
          ' Again change "MyTable" to whatever the table name
          should be
          com.CommandText = "Select * From MyTable"
          Dim da As New SqlDataAdapter( com)
          Using (da)
          Dim dt As New DataTable("MyTa ble")
          Using (dt)
          da.Fill(dt)
          Dim dgv As New DataGridView()
          dgv.Dock = DockStyle.Fill
          dgv.DataSource = dt
          Me.Controls.Add (dgv)
          End Using
          End Using
          End Using
          End Using
          End Sub
          >
          Hope that helps.
          >
          Thanks,
          >
          Seth Rowe
          >
          Ok, this help me a lot but i want to open a data base that i don't
          know the name
          i want that the program browse the tables of the base
          Thanks

          Comment

          • Omar Abid

            #6
            Re: Microsoft SQL Server 2005 Express

            On 29 mar, 15:16, "rowe_newsgroup s" <rowe_em...@yah oo.comwrote:
            Ok, this help me a lot but i want to open a data base that i don't
            know the name
            i want that the program browse the tables of the base
            >
            Do you know the information for the connection string? If you can
            connect to the database you can just query the schema tables and get a
            list of names.
            >
            Thanks,
            >
            Seth Rowe
            >
            On Mar 29, 8:26 am, "Omar Abid" <omar.abid2...@ gmail.comwrote:
            >
            >
            >
            On 28 mar, 13:14, "rowe_newsgroup s" <rowe_em...@yah oo.comwrote:
            >
            On Mar 28, 6:41 am, "Omar Abid" <omar.abid2...@ gmail.comwrote:
            >
            Hi,
            I'm Trying to make a program with vb2005express that connect to any
            Microsft SQL data base and show it's table. I'm having some problems
            can anyone help me?
            Omar Abid
            >
            You don't actually say what problems you're having, so I'm going to
            assume you can't get anything to work. So as a demo just start a new
            Windows Application and add something like this to a new form's code:
            >
            ' Typed in the message so watch out!
            >
            ' Add this to the top of the class
            Imports System.Data.Sql Client
            >
            Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
            System.EventArg s) Handles MyBase.Load
            ' This is your connection string fromwww.connect ionstrings.com
            ' Be sure to change the necessary parts before running
            Dim conn As New SqlConnection(" Data
            Source=myServer Address;Initial Catalog=myDataB ase;User
            Id=myUsername;P assword=myPassw ord;")
            Using (conn)
            conn.Open()
            Dim com As SqlCommand = conn.CreateComm and()
            Using (com)
            com.CommandType = CommandType.Tex t
            ' Again change "MyTable" to whatever the table name
            should be
            com.CommandText = "Select * From MyTable"
            Dim da As New SqlDataAdapter( com)
            Using (da)
            Dim dt As New DataTable("MyTa ble")
            Using (dt)
            da.Fill(dt)
            Dim dgv As New DataGridView()
            dgv.Dock = DockStyle.Fill
            dgv.DataSource = dt
            Me.Controls.Add (dgv)
            End Using
            End Using
            End Using
            End Using
            End Sub
            >
            Hope that helps.
            >
            Thanks,
            >
            Seth Rowe
            >
            Ok, this help me a lot but i want to open a data base that i don't
            know the name
            i want that the program browse the tables of the base
            Thanks- Masquer le texte des messages précédents -
            >
            - Afficher le texte des messages précédents -
            Hi,
            Now i can access to any table in my data base, but i want that the
            user choose a table.
            So i need to make a code that allow me to browser all the database
            tables.
            Omar Abid

            Comment

            • rowe_newsgroups

              #7
              Re: Microsoft SQL Server 2005 Express

              On Mar 31, 5:32 am, "Omar Abid" <omar.abid2...@ gmail.comwrote:
              On 29 mar, 15:16, "rowe_newsgroup s" <rowe_em...@yah oo.comwrote:
              >
              >
              >
              Ok, this help me a lot but i want to open a data base that i don't
              know the name
              i want that the program browse the tables of the base
              >
              Do you know the information for the connection string? If you can
              connect to the database you can just query the schema tables and get a
              list of names.
              >
              Thanks,
              >
              Seth Rowe
              >
              On Mar 29, 8:26 am, "Omar Abid" <omar.abid2...@ gmail.comwrote:
              >
              On 28 mar, 13:14, "rowe_newsgroup s" <rowe_em...@yah oo.comwrote:
              >
              On Mar 28, 6:41 am, "Omar Abid" <omar.abid2...@ gmail.comwrote:
              >
              Hi,
              I'm Trying to make a program with vb2005express that connect to any
              Microsft SQL data base and show it's table. I'm having some problems
              can anyone help me?
              Omar Abid
              >
              You don't actually say what problems you're having, so I'm going to
              assume you can't get anything to work. So as a demo just start a new
              Windows Application and add something like this to a new form's code:
              >
              ' Typed in the message so watch out!
              >
              ' Add this to the top of the class
              Imports System.Data.Sql Client
              >
              Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
              System.EventArg s) Handles MyBase.Load
              ' This is your connection string fromwww.connect ionstrings.com
              ' Be sure to change the necessary parts before running
              Dim conn As New SqlConnection(" Data
              Source=myServer Address;Initial Catalog=myDataB ase;User
              Id=myUsername;P assword=myPassw ord;")
              Using (conn)
              conn.Open()
              Dim com As SqlCommand = conn.CreateComm and()
              Using (com)
              com.CommandType = CommandType.Tex t
              ' Again change "MyTable" to whatever the table name
              should be
              com.CommandText = "Select * From MyTable"
              Dim da As New SqlDataAdapter( com)
              Using (da)
              Dim dt As New DataTable("MyTa ble")
              Using (dt)
              da.Fill(dt)
              Dim dgv As New DataGridView()
              dgv.Dock = DockStyle.Fill
              dgv.DataSource = dt
              Me.Controls.Add (dgv)
              End Using
              End Using
              End Using
              End Using
              End Sub
              >
              Hope that helps.
              >
              Thanks,
              >
              Seth Rowe
              >
              Ok, this help me a lot but i want to open a data base that i don't
              know the name
              i want that the program browse the tables of the base
              Thanks- Masquer le texte des messages précédents -
              >
              - Afficher le texte des messages précédents -
              >
              Hi,
              Now i can access to any table in my data base, but i want that the
              user choose a table.
              So i need to make a code that allow me to browser all the database
              tables.
              Omar Abid
              Like I mentioned in my last post, what you need to do to get the table
              names is query the schema tables. Use something like this as:

              Select Distinct TABLE_NAME
              From INFORMATION_SCH EMA.COLUMNS

              You'll need to mess around with the Where statement to get rid of
              system tables, etc, but I don't have Sql Server available right know
              to help.

              Thanks,

              Seth Rowe

              Comment

              • RobinS

                #8
                Re: Microsoft SQL Server 2005 Express


                "rowe_newsgroup s" <rowe_email@yah oo.comwrote in message
                news:1175355687 .655762.230460@ y66g2000hsf.goo glegroups.com.. .
                On Mar 31, 5:32 am, "Omar Abid" <omar.abid2...@ gmail.comwrote:
                On 29 mar, 15:16, "rowe_newsgroup s" <rowe_em...@yah oo.comwrote:
                >
                >
                >
                Ok, this help me a lot but i want to open a data base that i don't
                know the name
                i want that the program browse the tables of the base
                >
                Do you know the information for the connection string? If you can
                connect to the database you can just query the schema tables and get a
                list of names.
                >
                Thanks,
                >
                Seth Rowe
                >
                On Mar 29, 8:26 am, "Omar Abid" <omar.abid2...@ gmail.comwrote:
                >
                On 28 mar, 13:14, "rowe_newsgroup s" <rowe_em...@yah oo.comwrote:
                >
                On Mar 28, 6:41 am, "Omar Abid" <omar.abid2...@ gmail.comwrote:
                >
                Hi,
                I'm Trying to make a program with vb2005express that connect to
                any
                Microsft SQL data base and show it's table. I'm having some
                problems
                can anyone help me?
                Omar Abid
                >
                You don't actually say what problems you're having, so I'm going to
                assume you can't get anything to work. So as a demo just start a
                new
                Windows Application and add something like this to a new form's
                code:
                >
                ' Typed in the message so watch out!
                >
                ' Add this to the top of the class
                Imports System.Data.Sql Client
                >
                Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e
                As
                System.EventArg s) Handles MyBase.Load
                ' This is your connection string
                fromwww.connect ionstrings.com
                ' Be sure to change the necessary parts before running
                Dim conn As New SqlConnection(" Data
                Source=myServer Address;Initial Catalog=myDataB ase;User
                Id=myUsername;P assword=myPassw ord;")
                Using (conn)
                conn.Open()
                Dim com As SqlCommand = conn.CreateComm and()
                Using (com)
                com.CommandType = CommandType.Tex t
                ' Again change "MyTable" to whatever the table name
                should be
                com.CommandText = "Select * From MyTable"
                Dim da As New SqlDataAdapter( com)
                Using (da)
                Dim dt As New DataTable("MyTa ble")
                Using (dt)
                da.Fill(dt)
                Dim dgv As New DataGridView()
                dgv.Dock = DockStyle.Fill
                dgv.DataSource = dt
                Me.Controls.Add (dgv)
                End Using
                End Using
                End Using
                End Using
                End Sub
                >
                Hope that helps.
                >
                Thanks,
                >
                Seth Rowe
                >
                Ok, this help me a lot but i want to open a data base that i don't
                know the name
                i want that the program browse the tables of the base
                Thanks- Masquer le texte des messages précédents -
                >
                - Afficher le texte des messages précédents -
                >
                Hi,
                Now i can access to any table in my data base, but i want that the
                user choose a table.
                So i need to make a code that allow me to browser all the database
                tables.
                Omar Abid
                Like I mentioned in my last post, what you need to do to get the table
                names is query the schema tables. Use something like this as:

                Select Distinct TABLE_NAME
                From INFORMATION_SCH EMA.COLUMNS

                You'll need to mess around with the Where statement to get rid of
                system tables, etc, but I don't have Sql Server available right know
                to help.

                Thanks,

                Seth Rowe
                ---------------------------------------------------

                Here ya go.


                Dim cn As New SqlConnection(c onnectionString )
                Try
                cn.Open()
                'The Restrictions are: table_catalog, table_schema,
                ' table_name, table_type.
                'For my case, the table_catalog is the database name.
                'table_Schema is the owner.
                'Table_name is nothing because I want all tables.
                'table_type is "BASE TABLE".
                Dim restrictions() As String = New String() _
                {My.Settings.Da tabaseName, "dbo", Nothing, "BASE TABLE"}
                Dim dt As DataTable = cn.GetSchema("T ables", restrictions)

                'Uncomment this if you want to see the columns you can
                ' access from the GetSchema command.
                'I'm leaving it in here for future reference.
                'For Each col As DataColumn In dt.Columns
                ' Debug.Print(col .ColumnName.ToS tring)
                'Next

                For Each rw As DataRow In dt.Rows

                'Uncomment this if you want to see the values
                ' for each of these columns.
                'I'm leaving it in here for future reference.
                'Debug.Print("T able_Catalog = {0}, Table_Schema = {1},
                Table_Name = {2}, Table_Type = {3}", _
                ' rw.Item("TABLE_ CATALOG"), rw.Item("TABLE_ SCHEMA"), _
                ' rw.Item("TABLE_ NAME"), rw.Item("TABLE_ TYPE"))

                'sysdiagrams shows up if you have a database diagram;
                exclude it here
                If rw.Item("TABLE_ NAME").ToString .ToUpper <"SYSDIAGRAMS "
                Then
                Me.Add(rw.Item( "TABLE_NAME").T oString)
                End If
                Next

                'sort the list of tables
                Me.Sort()

                Catch
                MessageBox.Show ("Error opening connection to database.")
                Finally
                cn.Close()
                End Try
                End Sub


                Robin S.


                Comment

                • Omar Abid

                  #9
                  Re: Microsoft SQL Server 2005 Express

                  On 1 avr, 08:04, "RobinS" <Rob...@NoSpam. yah.nonewrote:
                  "rowe_newsgroup s" <rowe_em...@yah oo.comwrote in message
                  >
                  news:1175355687 .655762.230460@ y66g2000hsf.goo glegroups.com.. .
                  On Mar 31, 5:32 am, "Omar Abid" <omar.abid2...@ gmail.comwrote:
                  >
                  >
                  >
                  >
                  >
                  On 29 mar, 15:16, "rowe_newsgroup s" <rowe_em...@yah oo.comwrote:
                  >
                  Ok, this help me a lot but i want to open a data base that i don't
                  know the name
                  i want that the program browse the tables of the base
                  >
                  Do you know the information for the connection string? If you can
                  connect to the database you can just query the schema tables and get a
                  list of names.
                  >
                  Thanks,
                  >
                  Seth Rowe
                  >
                  On Mar 29, 8:26 am, "Omar Abid" <omar.abid2...@ gmail.comwrote:
                  >
                  On 28 mar, 13:14, "rowe_newsgroup s" <rowe_em...@yah oo.comwrote:
                  >
                  On Mar 28, 6:41 am, "Omar Abid" <omar.abid2...@ gmail.comwrote:
                  >
                  Hi,
                  I'm Trying to make a program with vb2005express that connect to
                  any
                  Microsft SQL data base and show it's table. I'm having some
                  problems
                  can anyone help me?
                  Omar Abid
                  >
                  You don't actually say what problems you're having, so I'm going to
                  assume you can't get anything to work. So as a demo just start a
                  new
                  Windows Application and add something like this to a new form's
                  code:
                  >
                  ' Typed in the message so watch out!
                  >
                  ' Add this to the top of the class
                  Imports System.Data.Sql Client
                  >
                  Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e
                  As
                  System.EventArg s) Handles MyBase.Load
                  ' This is your connection string
                  fromwww.connect ionstrings.com
                  ' Be sure to change the necessary parts before running
                  Dim conn As New SqlConnection(" Data
                  Source=myServer Address;Initial Catalog=myDataB ase;User
                  Id=myUsername;P assword=myPassw ord;")
                  Using (conn)
                  conn.Open()
                  Dim com As SqlCommand = conn.CreateComm and()
                  Using (com)
                  com.CommandType = CommandType.Tex t
                  ' Again change "MyTable" to whatever the table name
                  should be
                  com.CommandText = "Select * From MyTable"
                  Dim da As New SqlDataAdapter( com)
                  Using (da)
                  Dim dt As New DataTable("MyTa ble")
                  Using (dt)
                  da.Fill(dt)
                  Dim dgv As New DataGridView()
                  dgv.Dock = DockStyle.Fill
                  dgv.DataSource = dt
                  Me.Controls.Add (dgv)
                  End Using
                  End Using
                  End Using
                  End Using
                  End Sub
                  >
                  Hope that helps.
                  >
                  Thanks,
                  >
                  Seth Rowe
                  >
                  Ok, this help me a lot but i want to open a data base that i don't
                  know the name
                  i want that the program browse the tables of the base
                  Thanks- Masquer le texte des messages précédents -
                  >
                  - Afficher le texte des messages précédents -
                  >
                  Hi,
                  Now i can access to any table in my data base, but i want that the
                  user choose a table.
                  So i need to make a code that allow me to browser all the database
                  tables.
                  Omar Abid
                  >
                  Like I mentioned in my last post, what you need to do to get the table
                  names is query the schema tables. Use something like this as:
                  >
                  Select Distinct TABLE_NAME
                  From INFORMATION_SCH EMA.COLUMNS
                  >
                  You'll need to mess around with the Where statement to get rid of
                  system tables, etc, but I don't have Sql Server available right know
                  to help.
                  >
                  Thanks,
                  >
                  Seth Rowe
                  ---------------------------------------------------
                  >
                  Here ya go.
                  >
                  Dim cn As New SqlConnection(c onnectionString )
                  Try
                  cn.Open()
                  'The Restrictions are: table_catalog, table_schema,
                  ' table_name, table_type.
                  'For my case, the table_catalog is the database name.
                  'table_Schema is the owner.
                  'Table_name is nothing because I want all tables.
                  'table_type is "BASE TABLE".
                  Dim restrictions() As String = New String() _
                  {My.Settings.Da tabaseName, "dbo", Nothing, "BASE TABLE"}
                  Dim dt As DataTable = cn.GetSchema("T ables", restrictions)
                  >
                  'Uncomment this if you want to see the columns you can
                  ' access from the GetSchema command.
                  'I'm leaving it in here for future reference.
                  'For Each col As DataColumn In dt.Columns
                  ' Debug.Print(col .ColumnName.ToS tring)
                  'Next
                  >
                  For Each rw As DataRow In dt.Rows
                  >
                  'Uncomment this if you want to see the values
                  ' for each of these columns.
                  'I'm leaving it in here for future reference.
                  'Debug.Print("T able_Catalog = {0}, Table_Schema = {1},
                  Table_Name = {2}, Table_Type = {3}", _
                  ' rw.Item("TABLE_ CATALOG"), rw.Item("TABLE_ SCHEMA"), _
                  ' rw.Item("TABLE_ NAME"), rw.Item("TABLE_ TYPE"))
                  >
                  'sysdiagrams shows up if you have a database diagram;
                  exclude it here
                  If rw.Item("TABLE_ NAME").ToString .ToUpper <"SYSDIAGRAMS "
                  Then
                  Me.Add(rw.Item( "TABLE_NAME").T oString)
                  End If
                  Next
                  >
                  'sort the list of tables
                  Me.Sort()
                  >
                  Catch
                  MessageBox.Show ("Error opening connection to database.")
                  Finally
                  cn.Close()
                  End Try
                  End Sub
                  >
                  Robin S.- Masquer le texte des messages précédents -
                  >
                  - Afficher le texte des messages précédents -
                  Hi,
                  I tried tried and then your code after so changement works
                  Thanks a lot for resolving my probelm
                  If you need me : omar.abid2006@g mail.com
                  Thank you friend
                  OMAR ABID

                  Comment

                  Working...