mushin
Programmer
- Oct 4, 2000
- 49
From an array of primary keys, what is the best method to
retrieve that row and it's subsequent elements ?
This code populates a datagrid and then the array of keys.
=============================================================
Private Sub PopulateImageBrowser()
Dim DApics As New SqlDataAdapter
Dim selectCmd As SqlCommand = New SqlCommand("Select * from Picture", cnSQL)
selectCmd.CommandTimeout = 15
DApics.SelectCommand = selectCmd
cnSQL.Open()
Try
DApics.Fill(DSpics, "Picture")
Catch ex As Exception
MsgBox("Picture Not Found for this Search")
End Try
cnSQL.Close()
' DTpics = DSpics.Tables(0)
DV = New DataView(DSpics.Tables("Picture"))
dgImages.DataSource = DV
DV.Sort = "PictureId"
End Sub
Private Sub populatePictureArray()
' read thru datagrid, store picture table keys
Dim myRow As DataRow
iMax = 0
For Each myRow In DSpics.Tables("Picture").Rows
arrPictureKeys(iMax) = CInt(myRow("pictureid"))
iMax = iMax + 1
Next
tb_max.Text = iMax.ToString
End Sub
===========================================================
If I can read thru the dataset to get the keys, what do I have to do to use each of those keys, in turn,
to access the desired row and retieve a specific data element within it ?
I have tried the following:
(1)
If iCount < iMax Then
iCount = iCount + 1
searchKey = arrPictureKeys(iCount)
' myFoundRow = DSpics.Tables("Picture").Rows.Find(searchKey)
This fails with an error the the table has no primary-key,
which is untrue, it does (PictureId).
(2)
Dim i As Integer
Dim k As Integer
k = dv.Table.Rows.Count
i = dv.Find(searchKey)
if i < 0 Or i > k Then
MsgBox("Nothing Found, crap !")
Else
MsgBox("Found it")
End If
This works but I have no idea how to then retrieve the
fields from the dataView, nor do I understand why I cannot search directly on the dataset since I can access it.
Obviously I am missing something basic here, but what ?
retrieve that row and it's subsequent elements ?
This code populates a datagrid and then the array of keys.
=============================================================
Private Sub PopulateImageBrowser()
Dim DApics As New SqlDataAdapter
Dim selectCmd As SqlCommand = New SqlCommand("Select * from Picture", cnSQL)
selectCmd.CommandTimeout = 15
DApics.SelectCommand = selectCmd
cnSQL.Open()
Try
DApics.Fill(DSpics, "Picture")
Catch ex As Exception
MsgBox("Picture Not Found for this Search")
End Try
cnSQL.Close()
' DTpics = DSpics.Tables(0)
DV = New DataView(DSpics.Tables("Picture"))
dgImages.DataSource = DV
DV.Sort = "PictureId"
End Sub
Private Sub populatePictureArray()
' read thru datagrid, store picture table keys
Dim myRow As DataRow
iMax = 0
For Each myRow In DSpics.Tables("Picture").Rows
arrPictureKeys(iMax) = CInt(myRow("pictureid"))
iMax = iMax + 1
Next
tb_max.Text = iMax.ToString
End Sub
===========================================================
If I can read thru the dataset to get the keys, what do I have to do to use each of those keys, in turn,
to access the desired row and retieve a specific data element within it ?
I have tried the following:
(1)
If iCount < iMax Then
iCount = iCount + 1
searchKey = arrPictureKeys(iCount)
' myFoundRow = DSpics.Tables("Picture").Rows.Find(searchKey)
This fails with an error the the table has no primary-key,
which is untrue, it does (PictureId).
(2)
Dim i As Integer
Dim k As Integer
k = dv.Table.Rows.Count
i = dv.Find(searchKey)
if i < 0 Or i > k Then
MsgBox("Nothing Found, crap !")
Else
MsgBox("Found it")
End If
This works but I have no idea how to then retrieve the
fields from the dataView, nor do I understand why I cannot search directly on the dataset since I can access it.
Obviously I am missing something basic here, but what ?