阅读表使用阅读器ASP.NET和VB

时间:2011-12-13 22:17:52

标签: asp.net visual-studio-2010 sql-server-2008-r2

我有一个患者页面的视图,它显示了所有患者,并且每个患者旁边都有一个链接,可以将您带到另一个页面,用户可以使用文本框和下拉列表更新患者的信息。我使用查询字符串选择某个患者和读者命令从数据库中读取..
问题是读者根本没有访问该表..你能帮帮我吗?

pid = Request.QueryString("Pateint_ID")

Dim tempQuery As String = "SELECT     P.first_name, P.sec_name, P.third_name, P.last_name, P.Gender, PATA.ApplicationStatus," & _
        "P.DoB, P.birthplace, P.Nationality, P.patient_ID, P.issue_date, P.issue_place, P.city, " & _
        "P.Area,h.Name , h.DialysisCetner, p.Mobile_No, p.Work_phone, p.PhoneNo, p.Zipcode, p.POBox, p.problemWithDialysis" & _
        "FROM         Association AS A INNER JOIN PatientApplyToAssociation AS PATA INNER JOIN" & _
        "patient AS P ON PATA.patient_ID = P.patient_ID ON A.Association_ID = PATA.Association_ID INNER JOIN " & _
        "hospital AS H INNER JOIN TreatmentSession AS ts ON  ts.Name = H.Name ON p.patient_ID = ts.patient_ID LEFT OUTER JOIN Family AS F INNER JOIN" & _
        "Gardian AS G ON F.family_ID = G.GID INNER JOIN Relates AS R ON F.family_ID = R.family_ID ON P.patient_ID = R.patient_ID" & _
        "WHERE     (P.patient_ID = pid )"

    Dim query As String = String.Format(tempQuery, pid)

    Dim comm As New SqlCommand(query, con)

    Dim reader As SqlDataReader

    Try

        con.Open()

        reader = comm.ExecuteReader()

        If reader.Read() Then
            txtFirstName.Text = reader("first_name").ToString()
            txtFatherName.Text = reader("sec_name").ToString()
            txtGrandName.Text = reader("third_name").ToString()
            txtFamilyName.Text = reader("last_name").ToString()
            rblGender.SelectedValue = reader("Gender").ToString()
            txtBirthdate.Text = reader("DoB").ToString()
            ddlBirthPlace.SelectedValue = reader("birthplace").ToString()
            txtNationality.Text = reader("Nationality").ToString()
            txtIDCard.Text = reader("patient_ID").ToString()
            ddlIssuePlace.SelectedValue = reader("issue_place").ToString()
            txtIssuedate.Text = reader("issue_date").ToString()
            ddlAddressCity.SelectedValue = reader("city").ToString()
            ddlAddressRegion.SelectedValue = reader("area").ToString()

        End If

    Catch ex As Exception
        MsgBox("somthing's wrong")

    Finally
        con.Close()
    End Try 

1 个答案:

答案 0 :(得分:0)

根据您的上一条评论,我猜测它是一个SQL问题。我会先查询并在查询分析器中运行它以确保其有效。

您的查询看起来不正确。 清理完查询后,我注意到了这个

SELECT     P.first_name, P.sec_name, P.third_name, P.last_name, P.Gender, PATA.ApplicationStatus,
    P.DoB, P.birthplace, P.Nationality, P.patient_ID, P.issue_date, P.issue_place, P.city, 
    P.Area,h.Name , h.DialysisCetner, p.Mobile_No, p.Work_phone, p.PhoneNo, p.Zipcode, p.POBox, p.problemWithDialysis
    FROM         Association AS A INNER JOIN PatientApplyToAssociation AS PATA 
    INNER JOIN patient AS P ON PATA.patient_ID = P.patient_ID ON A.Association_ID = PATA.Association_ID 
    INNER JOIN hospital AS H 
    INNER JOIN TreatmentSession AS ts ON  ts.Name = H.Name ON p.patient_ID = ts.patient_ID 
    LEFT OUTER JOIN Family AS F 
    INNER JOIN Gardian AS G ON F.family_ID = G.GID INNER JOIN Relates AS R ON F.family_ID = R.family_ID ON P.patient_ID = R.patient_ID
    WHERE     (P.patient_ID = pid )

注意你的联接2中没有ON条款?更不用说你有3个连接有多个ON子句?