[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 207
  • Last Modified:

Problems Internet Information Service (IIS) Datagrid or table

Hie Guys

I want to display data in an access database table on a data grid to be presented in an IIS Application. L also want each row on that datagrid to link to a different page.

Looking forward to your assistance

Mike
0
nyathim
Asked:
nyathim
1 Solution
 
EasyWriterCommented:
1. Create a new Web App in VB.NET

2. Drop a button and a datagrid on the form

3. In this example I have a Microsoft Access database called EE2.MDB with a table called EMPLOYEE.  The table has two fields, an EMP_NAME and an EMP_WEBSITE.  You will need to substitute your own database information in the following code.

4. Paste this code

    Private Sub FillDataGrid()
        Dim oledb_Cn As Data.OleDb.OleDbConnection
        Dim oledb_Da As Data.OleDb.OleDbDataAdapter
        Dim sCn As String
        Dim dsDataSet As New DataSet
        Dim sSQL As String

        Try
            'create a connection string
            sCn = ""
            sCn = sCn & "Provider=Microsoft.Jet.OLEDB.4.0;"
            sCn = sCn & "Data Source=C:\EE2.MDB;"
            sCn = sCn & "Persist Security Info=False"

            'create a SQL string
            sSQL = "SELECT * FROM EMPLOYEE "

            'create oledb objects
            oledb_Cn = New Data.OleDb.OleDbConnection(sCn)
            oledb_Da = New Data.OleDb.OleDbDataAdapter(sSQL, oledb_Cn)

            'fill the dataset
            oledb_Da.Fill(dsDataSet, "EMPLOYEE ")

            'bind the grid
            DataGrid2.DataSource = dsDataSet.Tables("EMPLOYEE ").DefaultView
            DataGrid2.DataBind()

        Catch ex As Exception
            '"Data error encountered: " & ex.Message.ToString
        End Try

    End Sub

5. Make the above code work with your database: Change C:\EE2.MDB in on place in the above code.  Change the SQL statement.  And change the table name EMPLOYEE in two places.

6. Make your button run the code, and test it to make sure it is showing the data in the grid (the hyperlinks won't be there yet.)

7. If you have a field in your database that contains URLs, you get them to show as  hyperlinks by right clicking your DataGrid in the design window, and selecting "Property Builder..."  On the left, click the second item down called "COLUMNS".  In the Available Columns list, select HYPERLINK COLUMN and push the button with the > sign to put it into the selected columns list.  Then configure your new hyperlink column by filling in the TEXT FIELD and the URL FIELD boxes.  

The URL field is the name of the database field that holds the actual web site URLs.  The TEXT field is for the database field that shows what you want the link to say.  For example, I wanted it to show the name BOB and when the user clicks his name it it goes to bob's favorite search engine.  So in the TEXT FIELD I typed EMP_NAME and in the URL FIELD I typed EMP_WEBSITE.  You will simply need to substitute your database field names approriately.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now