在数据库

时间:2016-06-11 14:34:15

标签: mysql asp.net vb.net visual-studio-2013

我正在创建一个网站,允许患者登录并查看自己的数据。到目前为止,当他们登录时,他们被重定向到user.aspx页面,会话在Patient表的标签上显示他们的用户名(我已经包含会话信息以帮助解决问题)...但我还想要一张桌子显示患者相应的医学信息:

患者表(所有表格均为虚拟数据):

patient table

药品表:

Medicine

登录后的会话在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

标签在user.aspx中的标签中显示用户名:

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

我有另一张名为处方(链接表)的表,它有复合键Patientid(来自Patient table)和Medicine(来自医学表) - 两个外键。

enter image description here

当用户登录时,如何显示Medicine表以显示用户的相应药物以及user.aspx上表格中的信息(名称,目的,说明)。我会使用Toolbox的gridview做到这一点吗?

不知道我在哪里解决这个问题

enter image description here

错误: enter image description here

1 个答案:

答案 0 :(得分:1)

是的,只需在user.aspx页面的工具箱中添加gridview,然后在user.aspx页面的页面加载事件上运行以下代码行

<%@ 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>

您的aspx页面代码将是

{{1}}