我正在创建一个允许患者登录并查看他们自己的数据的网站。到目前为止,当他们登录时,他们将被重定向到user.aspx页,并且一个会话将其用户名显示在Patient表的标签上(我已经包括了会话信息以帮助解决问题)...但是我也想要一个表显示患者相应的药物信息:
患者表(所有表都是伪数据):
药桌:
登录后的会话在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表)和Medicine(来自Medicine表)-都是外键。
当用户登录时,如何获取Medicine表以显示用户相应的药物以及user.aspx上该表中的信息(名称,目的,说明)。我可以使用Toolbox中的gridview来做到这一点吗?
不确定我的解决方案在哪里出问题
是的,只需在user.aspx页面的工具箱中添加gridview,然后在user.aspx页面的页面加载事件上运行下面的代码行
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
而且您的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
</span>
</p>
<asp:GridView ID="GridView1" runat="server" ></asp:GridView>
</asp:Content>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句