Display a table on a webpage from database

laurajs

I am creating a website that allows a patient to log in and see their own data. So far when they log in they are redirected to the user.aspx page and a session displays their username on a label from the Patient table( I have included the session information to help with the question) ... But I also want a table to display the patients corresponding medicine information:

The patient table (all tables are dummy data):

patient table

The medicine table:

Medicine

The session after login is authenticated in login.aspx:

Public Function CheckUser(username As String, password As String) As Integer
    Dim cmdstring As String = "SELECT * FROM Patient  Where Username=@USERNAME AND Password=@PASSWORD"
    Dim found = 0
    Using conn As New SqlConnection("Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Laura\Final_proj\App_Data\surgerydb.mdf;Integrated Security=True;Connect Timeout=30")

        Dim cmd = New SqlCommand(cmdstring, conn)
        cmd.Parameters.Add("@USERNAME", SqlDbType.NChar).Value = username
        cmd.Parameters.Add("@PASSWORD", SqlDbType.NChar).Value = password
        conn.Open()



        Dim reader = cmd.ExecuteReader()

        While reader.Read()
            Session("PatientId") = CInt(reader.Item("PatientId"))
            Session("Username") = CStr(reader.Item("Username"))
            found = CInt(reader.Item("PatientId"))
        End While

        reader.Close()
    End Using
    Return (found)
End Function

Label displaying user name in label in user.aspx:

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    Label1.Text = Session("Username")
End Sub

I have another table called prescription (link table) that has composite keys Patientid (from Patient table) and Medicine (from medicine table) - both foreign keys.

enter image description here

When the user logs in how can I get the Medicine table to display showing the user's corresponding medicine and the information from the table (Name, Purpose, Instructions) on user.aspx. Will I do this using a gridview from Toolbox?

Not sure where I am going wrong with the solution here

enter image description here

errors: enter image description here

Nazir Ullah

yea simply add the gridview from toolbox in user.aspx page and run the below line of code on page load event of user.aspx page

Partial Class Pages_user
    Inherits System.Web.UI.Page

    Sub Page_Load(ByVal Sender As System.Object, ByVal e As System.EventArgs)

        If Not IsPostBack Then
            Dim conn As New System.Data.SqlClient.SqlConnection("Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Laura\Final_proj\App_Data\surgerydb.mdf;Integrated Security=True;Connect Timeout=30")
            Dim cmdstring As String = "SELECT pt.PatientId, pt.ForeName, pt.Username, md.Name, md.Purpose, md.Instrcutions  " +
                                        "FROM Patient pt INNER JOIN prescription pr ON pt.PatientId = pr.PatientId  " +
                                        "INNER JOIN medicine md ON md.MedicineId = pr.MedicineId Where pt.PatientId  = @PatientId"
            Dim dt As New System.Data.DataTable()
            Dim da As New System.Data.SqlClient.SqlDataAdapter(cmdstring, conn)
            da.SelectCommand.Parameters.Add("@PatientId", System.Data.SqlDbType.Int).Value = CInt(Session("PatientId").ToString())
            conn.Open()
            da.Fill(dt)
            conn.Close()

            GridView1.DataSource = dt
            GridView1.DataBind()
        End If

    End Sub
End Class

And your aspx page code will be

<%@ Page Title="" Language="VB" MasterPageFile="~/Masterpages/MasterPage2.master" AutoEventWireup="true" CodeFile="user.aspx.vb" Inherits="Pages_user" %>

<asp:Content ID="Content1" ContentPlaceHolderID="title" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="head" runat="Server">
    <style type="text/css">
        .auto-style2 {
            font-size: x-large;
        }
 </style>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="contentbody" runat="Server" Inherits="Pages_user" CodeFile="Pages_user.aspx.vb">

    <p>
       <span class="auto-style2">Please Select Your Medication&nbsp;&nbsp;&nbsp;
        </span>

    </p>

    <asp:GridView ID="GridView1" runat="server" ></asp:GridView>

</asp:Content>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Display info from a database on a webpage using php

From Dev

Display a league table on a webpage?

From Dev

Can't display other data from the database on to webpage

From Dev

Displaying a table from MySQL database onto webpage with Ruby Sinatra

From Dev

Display selected results only from the database table

From Dev

Display data from mysql database using a table

From Dev

Fetch data from database and display to table

From Dev

Display images from folder on webpage

From Dev

Display all the links from a webpage

From Dev

changing the value from database on the webpage

From Dev

Error: Display data form database to webpage

From Dev

how to display JSON output in asp.net webpage from sql database

From Dev

How can i store image and display it in webpage from database in laravel 4

From Dev

Display values from table from a database into a dropdown list

From Dev

Extracting a table from webpage with regex

From Dev

Extracting a table from webpage with regex

From Dev

Get data from webpage into a table

From Dev

rvest: Scraping table from webpage

From Dev

How to extract table from a webpage

From Dev

Display a database table in a jqGrid

From Dev

Codeigniter PHP pulling records from mysql database table to display on page

From Dev

Display data from database inside <table> using wordpress $wpdb

From Dev

how to display data from database in table view in python

From Dev

Spring MVC how to display data from database into a table

From Dev

Display odds from database table like they are in bookmaker sites

From Dev

Display data from database inside <table> using wordpress $wpdb

From Dev

How to display data from Sql Database in table in report viewer

From Dev

How to Display data from moodle database in an html table

From Dev

display dropdown selected values based on two table from database

Related Related

  1. 1

    Display info from a database on a webpage using php

  2. 2

    Display a league table on a webpage?

  3. 3

    Can't display other data from the database on to webpage

  4. 4

    Displaying a table from MySQL database onto webpage with Ruby Sinatra

  5. 5

    Display selected results only from the database table

  6. 6

    Display data from mysql database using a table

  7. 7

    Fetch data from database and display to table

  8. 8

    Display images from folder on webpage

  9. 9

    Display all the links from a webpage

  10. 10

    changing the value from database on the webpage

  11. 11

    Error: Display data form database to webpage

  12. 12

    how to display JSON output in asp.net webpage from sql database

  13. 13

    How can i store image and display it in webpage from database in laravel 4

  14. 14

    Display values from table from a database into a dropdown list

  15. 15

    Extracting a table from webpage with regex

  16. 16

    Extracting a table from webpage with regex

  17. 17

    Get data from webpage into a table

  18. 18

    rvest: Scraping table from webpage

  19. 19

    How to extract table from a webpage

  20. 20

    Display a database table in a jqGrid

  21. 21

    Codeigniter PHP pulling records from mysql database table to display on page

  22. 22

    Display data from database inside <table> using wordpress $wpdb

  23. 23

    how to display data from database in table view in python

  24. 24

    Spring MVC how to display data from database into a table

  25. 25

    Display odds from database table like they are in bookmaker sites

  26. 26

    Display data from database inside <table> using wordpress $wpdb

  27. 27

    How to display data from Sql Database in table in report viewer

  28. 28

    How to Display data from moodle database in an html table

  29. 29

    display dropdown selected values based on two table from database

HotTag

Archive