Click here to Skip to main content
15,896,544 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can't data to show in gridview or textboxes.

What I have tried:

My Code...
Imports System.Data.SqlClient
Imports System.Data
Imports Microsoft.AspNet.Identity
Imports Microsoft.AspNet.Identity.EntityFramework
Imports Microsoft.AspNet.Identity.Owin
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports Microsoft.Owin.Security
Imports System.Runtime.InteropServices

Partial Class PatientMedicationHistory
    Inherits System.Web.UI.Page

    'Dim txtPatientName As New TextBox
    ' Dim txtPatientID As New TextBox
    ' Dim txtDOB As New TextBox
    Dim intZero As Integer
    Dim SQLCONN As New SqlConnection
    Dim SQLCMD As New SqlCommand
    Dim TempHistoryData As New DataTable()
    
    Protected Sub btEnterKey_Click(sender As Object, e As EventArgs) Handles btEnterKey.Click

            'check if temp table has data... This does no work always shows if intZero > 0
            SQLCMD.CommandText = ""
            SQLCMD.CommandType = CommandType.Text
            SQLCMD.CommandText = "Select "
            SQLCMD.CommandText = SQLCMD.CommandText & "intZero"
            SQLCMD.CommandText = SQLCMD.CommandText & " = COUNT(*) from TempHistoryData"

            If txtPatientID.Value <> "" Then
                SQLCMD.CommandText = SQLCMD.CommandText & " Where TempHistoryData.PatientID = '" & txtPatientID.Value & "'"
            ElseIf txtPatientName.Value <> "" Then
                SQLCMD.CommandText = SQLCMD.CommandText & " Where TempHistoryData.PatientName = '" & txtPatientName.Value & "'"
            End If

            Try
                SQLCMD.ExecuteNonQuery()
            Catch ex As Exception
                RecordErr.Text = "Recount Error intZero"
                RecordErr.Visible = True
                SQLCONN.Close()
                Exit Sub
            End Try

            If (intZero > 0) Then
                'Populate Patient Medication History Screen... No data shows in text boxes and gridview does not show on web page
                txtPatientID.Value = TempHistoryData("PatientID").ToString()
                txtPatientName.Value = TempHistoryData("PatientName").ToString()
                txtDOB.Value = TempHistoryData("DateOfBirth").ToString()

                GridView1.DataSource = TempHistoryData
                GridView1.DataBind()
            Else
                RecordErr.Text = "intZero Error"
                RecordErr.Visible = True
                SQLCONN.Close()
                Exit Sub
            End If

            SQLCONN.Close()
        Else
            RecordErr.Text = "Record Not Found"
            RecordErr.Visible = True
        End If
    End Sub
Posted
Comments
FranzBe 30-Oct-17 14:11pm    
ExecuteNonQuery() as the name implies executes a command, e.g. an update or delete command, that is NO query. What you need to do is ExecuteDataReader(). Try google "read data from sqldatareader", or as alternative "ado.net fill datatable"
When you look at your code: how do you think will intZero get its value?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900