【发布时间】:2016-06-24 15:16:10
【问题描述】:
我正在使用 asp.net 和 Visual Basic 创建一个网站。当用户登录时,他们会从 login.aspx 页面定向到 user.aspx 页面,并且会话会调出他们的用户名和一个网格(网格包含数据库中的登录用户药物,并带有一个用于选择的命令来选择药物 ID):
医生表中的DoctorId作为外键存储在患者表中
Pharmacy from 下拉框选+sql连接字符串:
MedicineId 来自网格
<asp:SqlDataSource ID="SqlPharm" runat="server" ConnectionString="<%$ ConnectionStrings:SurgeryConnectionString %>" SelectCommand="SELECT DISTINCT Pharmname FROM Pharmacy "></asp:SqlDataSource>
<asp:DropDownList ID="DropPharm" runat="server" DataSourceID="SqlPharm" DataTextField="Pharmname" DataValueField="Pharmname"></asp:DropDownList>
一旦在网格中选择了药物选项 已选择下拉列表药房 单击 AND 按钮我希望 Order_pres 更新下表:
这是我目前正在处理的代码,没有出现任何错误,当我测试这个没有任何更新时,希望其他人的知识可以指导我需要做什么来更新表格 - 包含的标签有用于测试拉取值并在运行时显示在标签上:
Protected Sub GridView1_RowCommand(sender As Object, e As GridViewCommandEventArgs)
lbldrop.Text = e.CommandArgument.ToString()
If e.CommandName = "UpdateMedicine" Then
Session("MedicineID") = Integer.Parse(e.CommandArgument.ToString())
End If
End Sub
Protected Sub btnconfirm_Click(sender As Object, e As EventArgs) Handles btnconfirm.Click
' Dropdown for pharmacy someVariable = DropPharm.SelectedItem.Value
Dim PatientId As Integer = Session("PatientId")
Dim PharmacyId As Integer = Session("PharmacyId")
Dim MedicineId As Integer = Session("MedicineID")
Dim DateOrdered As Date
' Get DoctorId from the patient table
Dim DoctorId As Integer = "SELECT DoctorId FROM Patient "
'.Value = CInt(Session("DoctorId").ToString())
Dim query As String = String.Empty
query &= "INSERT INTO Order_pres (PatientId, PharmacyId, "
query &= " DoctorId, [Date Ordered]) "
query &= "VALUES (@PatientId,@MedicineId, @PharmacyId, @DoctorId, @DateOrdered)"
Dim sqlCs As String = ConfigurationManager.ConnectionStrings("SurgeryConnectionString").ConnectionString
Using conn As New SqlConnection(sqlCs),
comm As New SqlCommand(query, conn)
With comm.Parameters
.Add("@PatientId", SqlDbType.Int).Value = Session("PatientId")
.Add("@DoctorId", SqlDbType.Int).Value = Session("DoctorId")
.Add("@MedicineId", SqlDbType.Int).Value = Session("MedicineID")
.Add("@PharmacyId", SqlDbType.Int).Value = Session("PharmacyId")
.Add("@DateOrdered", SqlDbType.DateTime).Value = DateTime.Parse(DateOrdered)
End With
Try
conn.Open()
Dim rowInserted = comm.ExecuteNonQuery()
If rowInserted = 1 Then
lblconfirm.Text = "Order Placed"
Else
lblnoconfirm.Text = "Order not placed"
End If
Catch ex As SqlException
lblnoconfirm.Text = "Unexpectd error: " & ex.Message
End Try
End Using
End Sub
网格持有medicineId:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowCommand="GridView1_RowCommand" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton runat="server" Text="Select" CommandName="UpdateMedicine" CommandArgument='<%# Eval("MedicineId") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Purpose" HeaderText="Purpose" />
<asp:BoundField DataField="Instrcutions" HeaderText="Instructions" />
</Columns>
</asp:GridView>
登录时存储的会话:
Dim reader = cmd.ExecuteReader()
While reader.Read()
Session("PatientId") = CInt(reader.Item("PatientId"))
Session("Username") = CStr(reader.Item("Username"))
Session("DoctorId") = CStr(reader.Item("DoctorId"))
found = CInt(reader.Item("PatientId"))
End While
更新过程中发生的步骤:
【问题讨论】:
-
4个参数传入,然后你给5个。在插入。身份证
标签: mysql asp.net vb.net visual-studio-2013