How can I display more fields in my dataGrid. I am able to display the accno but I want to be able to display other fields from my query. I am reading from an array into the datagrid, and here is my code.
Imports System.Data.sqlclient
Public Class Census
Public CNTR As Integer = 0
' Public ArrayOfAccounts(100000) As String
Public ArrayOfAccounts(100000) As Account
Function GetLastDay(ByVal aDate)
'Sets any date value to be the last day of the month
Dim dteFirstDayNextMonth
'dateValue = dteFirstDayNextMonth
dteFirstDayNextMonth = DateSerial(Year(aDate), Month(aDate) + 1, 1)
'GetLastDay = Day(DateAdd("d", -1, dteFirstDayNextMonth))
GetLastDay = DateSerial(Year(aDate), Month(aDate) + 1, 1 - 1)
End Function
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
' Build a connection to thomasdata table
' and populate the datareader with patient days
'-------------------------
----------
----------
---
'Dim DA_PatientDaysDlyCY As SqlDataAdapter
Dim CurrentDate As String
Dim cmbBoxVar As String
Dim theMonth As String
'Put things together for a date text value
theMonth = cmbDateRange.SelectedValue
'Uses microsofts calendar to take care of leap year
Dim theYear As String = Year(Today)
cmbBoxVar = theMonth + "/" + "01/" + theYear
' MsgBox(cmbBoxVar)
'Switch the month value to the last day of the month by calling the GetLastDay Func
'This should take care of leap years
CurrentDate = GetLastDay(cmbBoxVar)
'MsgBox(CurrentDate)
Dim dateBack As Date
'Dim dateBack2 As String
dateBack = DateAdd("d", -90, CurrentDate)
'dateBack2 = dateBack
'MsgBox(dateBack2)
'Dim tempdate As Date = dateBack2
Dim exitloop As Boolean
exitloop = False
Do While exitloop = False
'MsgBox(dateBack)
dateBack = DateAdd("d", 1, dateBack)
Call acctLookUp(dateBack)
If dateBack = CurrentDate Then
exitloop = True
End If
Loop
' MsgBox(ArrayOfAccounts)
'Array.Sort(ArrayOfAccount
s)
' Build a new array without duplicates
Call mysub()
'myArray.Sort()
'MsgBox(myArray.ToString)
'Dim source As New BindingSource
'source.DataSource = myArray.ToString
'dgridView.DataSource = source
End Sub
Private Sub acctLookUp(ByVal tempdate As Date)
'Query data to get ready to put into a sql table
Dim Conn_PatientDaysDlyCY As SqlConnection
Dim SqlSelect_PatientDaysDlyCY
As SqlCommand
Dim DS As New DataSet()
Dim myreaderCY As SqlDataReader
Dim ConnString As String = "*************************
**********
**********
**********
******"
Dim SelectStatementCY As String = "SELECT acctno, svc FROM vw_ThomasData" + _
" WHERE (admdate <= '" + tempdate + "' and + admdate <> '01/01/1900') " + _
"And (disdate > '" + tempdate + "' Or disdate = '01/01/1900') " + _
"And (svc = 'PSY' or svc = 'BHC') and totalrev <> 0" + _
" ORDER BY vw_ThomasData.admdate"
'Create SQL adaptor and populate it
Dim adaptor As SqlDataAdapter = New SqlDataAdapter(SelectState
mentCY, ConnString)
Dim cmdBuilder As SqlCommandBuilder = New SqlCommandBuilder(adaptor)
Conn_PatientDaysDlyCY = New SqlConnection(ConnString)
Conn_PatientDaysDlyCY.Open
()
SqlSelect_PatientDaysDlyCY
= New SqlCommand(SelectStatement
CY, Conn_PatientDaysDlyCY)
myreaderCY = SqlSelect_PatientDaysDlyCY
.ExecuteRe
ader
adaptor.Fill(DS)
'old loop through data
'For I = 0 To DS.Tables(0).Rows.Count - 1
' 'MsgBox(DS.Tables(0).Rows(
I).Item(0)
)
' 'DS.Tables(0).Rows(I).Item
(1) = 0
' ArrayOfAccounts(CNTR) = DS.Tables(0).Rows(I).Item(
0)
' 'trying to populate the dgridView for testing purposes
' CNTR = CNTR + 1
'Next
'loop through the records and load into array
Dim I As Integer
For I = 0 To DS.Tables(0).Rows.Count - 1
'MsgBox(DS.Tables(0).Rows(
I).Item(0)
)
'DS.Tables(0).Rows(I).Item
(1) = 0
Dim acc As New Account(DS.Tables(0).Rows(
I).Item(1)
.ToString(
))
ArrayOfAccounts(CNTR) = acc
CNTR = CNTR + 1
Next
'send array values using arrayOfAccounts Class to the DataGrid
dgridView.DataSource = ArrayOfAccounts
'Close Connection
Conn_PatientDaysDlyCY.Clos
e()
End Sub
Private Sub Census_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Populate the Combo Box
Dim list As New ArrayList()
list.Add(New DictionaryEntry("January",
"01"))
list.Add(New DictionaryEntry("February"
, "02"))
list.Add(New DictionaryEntry("March", "03"))
list.Add(New DictionaryEntry("April", "04"))
list.Add(New DictionaryEntry("May", "05"))
list.Add(New DictionaryEntry("June", "06"))
list.Add(New DictionaryEntry("July", "07"))
list.Add(New DictionaryEntry("August", "08"))
list.Add(New DictionaryEntry("September
", "09"))
list.Add(New DictionaryEntry("October",
"10"))
list.Add(New DictionaryEntry("November"
, "11"))
list.Add(New DictionaryEntry("December"
, "12"))
Me.cmbDateRange.DataSource
= list
Me.cmbDateRange.DisplayMem
ber = "Key"
Me.cmbDateRange.ValueMembe
r = "Value"
End Sub
Sub MySub()
Dim myArray(1000) As Account
For i As Integer = 0 To 999
myArray(i) = New Account(CStr(i))
Next
End Sub
End Class
Public Class Account
Public _myString As String
Public Sub New()
End Sub
Public Sub New(ByVal paramString As String)
_myString = paramString
End Sub
Public Property MyString() As String
Get
Return _myString
End Get
Set(ByVal value As String)
_myString = value
End Set
End Property
End Class
Start Free Trial