|
-
July 19th, 2005, 09:38 AM
#1
[SOLVED] datareader
hey,
got the following routine that checks if the first word in a listview is the same as the first word in a DB table.
My problem is that if they are not the same i want the routine to check the next listview record with the same DB record.
in other words, i need to push back the datareader one step (if possible) OR i'll need to change the way im looping
Code:
Dim a As Integer = 0
Dim dbReader As OleDb.OleDbDataReader
dbReader = cmd.ExecuteReader
If dbReader.HasRows Then
Do While dbReader.Read
a = a + 1
If dbReader("ReportName") = Me.ListView1.Items(a - 1).Text Then
If dbReader("View") = True Then
Me.ListView1.Items.Item(a - 1).Checked = True
End If
If dbReader("View") = False Then
Me.ListView1.Items.Item(a - 1).Checked = False
End If
Else
Me.ListView1.Items.Item(a - 1).Checked = False
End If
Loop
End If
thanks
Last edited by Nasty2; July 20th, 2005 at 01:42 AM.
-
July 19th, 2005, 10:32 AM
#2
Re: datareader
Nasty2,
not sure about your intentions, but something like this?
Code:
Do While dbReader.Read
For a = 0 to ListView1.Items.Count -1
If dbReader("ReportName") = ListView1.Items(a).Text Then
ListView1.Items.Item(a).Checked = dbReader("View")
Exit For
Else
ListView1.Items.Item(a).Checked = False
End If
Next
Loop
Hope it helps
---- Edited ----
Ooooops, no. Very bad code, don't use it . Hopefully my boss will not see it or my working days will be short . Only last record is usefull when done that way, forget it.
What do you want to do when you get a match? Read next record and continue analisis from the item where the last match ocurred? What if the match is on the last item?
Last edited by DeepButi; July 19th, 2005 at 10:41 AM.
Did it help? rate it.
The best conversation I had was over forty million years ago ... and that was with a coffee machine.
-
July 19th, 2005, 10:48 AM
#3
Re: datareader
I don't understand much your request...
From what I understand you're trying to get a Match in a datareader from a Listview item....
Why not transform the datareader in a dataset and then use the dataset
filter options ?
This is an example : Sorry for the French comments
Code:
'*******************************************************************************
'* *
'* Nom de la procédure : *
'* SQLProcData *
'* *
'* But : *
'* Excécute une procédure stockée qui retourne des données *
'* *
'* Parametres : *
'* *
'* byval ConnString as string : La connection string a utiliser. *
'* *
'* byref Reader as SQLClient.SqlDatareader : Le reader où on met les *
'* données *
'* *
'* *
'* *
'*******************************************************************************
Public Sub SQLProcData(ByVal ConnString As String, _
ByRef ds As DataSet, _
ByRef conn As SqlClient.SqlConnection, _
ByRef SQLProcsParams As Collection, _
ByVal ProcName As String)
Dim read As SqlClient.SqlDataReader
Dim cmd As New SqlClient.SqlCommand
Dim Param As SqlClient.SqlParameter
Dim dataTbl As DataTable
Dim datarw() As Object
Dim nwCol As DataColumn
Dim NwTable As DataTable
If conn Is Nothing Then
conn = New SqlClient.SqlConnection
Else
conn.Dispose()
conn = New SqlClient.SqlConnection
End If
conn.ConnectionString = ConnString
cmd.Connection = conn
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = ProcName
Dim i As SQLParam
' NOTE SQLPROCSPARAM IS A CLASS I MADE TO HOLD STORED PROC PARAMS
For Each i In SQLProcsParams
Param = cmd.CreateParameter()
Param.ParameterName = i.ParamName
Param.SqlDbType = i.ParamType
Param.Value = i.ParamValue
cmd.Parameters.Add(Param)
Next
conn.Open()
Try
read = cmd.ExecuteReader(CommandBehavior.Default)
Catch e As SqlClient.SqlException
' CHANGE THIS FOR YOUR OWN SAKES
End Try
' Remplir le dataset * partir du reader
If ds Is Nothing Then
ds = New DataSet
End If
If read.HasRows Then
dataTbl = read.GetSchemaTable()
NwTable = New DataTable
For Each j As DataRow In dataTbl.Rows
nwCol = New DataColumn
nwCol.Unique = CBool(j.Item("IsUnique"))
nwCol.DataType = CType(j.Item("Datatype"), System.Type)
nwCol.ColumnName = CStr(j.Item("ColumnName"))
nwCol.AllowDBNull = CBool(j.Item("AllowDbNull"))
NwTable.Columns.Add(nwCol)
Next
ReDim datarw(NwTable.Columns.Count - 1)
While read.Read()
read.GetValues(datarw)
NwTable.Rows.Add(datarw)
End While
ds.Tables.Add(NwTable)
End If
read.Close()
conn.Close()
End Sub
Nicolas Bohemier
-
July 19th, 2005, 01:56 PM
#4
Re: datareader
Solved it with the following code:
Code:
If dbReader.HasRows Then
Do While dbReader.Read
For Each lvi As ListViewItem In ListView1.Items
If dbReader("ReportName") = lvi.Text Then
If dbReader("View") = True Then
lvi.Checked = True
Else
lvi.Checked = False
End If
End If
Next
Loop
End If
Thanks anyway for your quick response
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|