Computing.Net > Forums > Programming > VB editing a recordset

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

VB editing a recordset

Reply to Message Icon

Original Message
Name: irfreh
Date: May 18, 2006 at 16:25:58 Pacific
Subject: VB editing a recordset
OS: win xp
CPU/Ram: :)
Model/Manufacturer: :(
Comment:

Hello post readers,

My problem is with a VB app that i am working on. The form has a Listview that brings up errors saying that there is no unique identifier, which is a result from the index key for the listview not being set. My boss has told me that he wants the recordset to have an incrementing value that can be used for the index.

My problem is that i have not got a clue.

I know there is prob a better and easier way to do this ie adjusting the stored proceudure but i got to do what the boss man says.

So how do i go about doing this. Code examples would be great.

example of how my app is laid out and where i need the code.

'***Recordset
rs = Recordset
(I need auto incrementing code here)
Listview, Recordset......

please not that the main thing that i am having trouble getting my head around is how do i go about adding my value to the end of the recordset.

ie. 1st record+1
2nd record+2
3rd record+3
And so on.....


I know i have rambled here and prob have confused you guys but i would greatly appreciate any help.

Thanks in advanced.


Report Offensive Message For Removal


Response Number 1
Name: Chi Happens
Date: May 22, 2006 at 07:55:18 Pacific
Reply: (edit)

the only way the id would be useful is if it is contained within the database itself. If you give arbitrary auto-incremented numbers to your records, there is no use for them.

Otherwise simply iterate through the recordset using a do while not RS.EOF and increment a value and add it to your listview.

Chi

They mostly come at night...mostly.


Report Offensive Follow Up For Removal

Response Number 2
Name: SamRock
Date: May 29, 2006 at 01:34:52 Pacific
Reply: (edit)

Hi,

I think ur Boss has completed confused an already confused U. But don't worry friend, this has happened to me many times.

Forget about incrementing the Recordset from database...
U can do it easily from VB.

From what I understand, U are facing problem with the Listview Index.
'' Here is my Sample Code, Its not Copyrighted ;) so u can use it
'*****************************************
Dim SQL As String
Dim rs As New Recordset
Dim Litem As ListItem
'' Replace this with ur Query
SQL = "Select * from EMP"
'' Opening the Recordset
rs.Open SQL, DB, adOpenForwardOnly, adLockReadOnly
'' Check If records retrived?
If Not rs.EOF Then
'' Loop tilll END of FILE
Do While Not rs.EOF
'' Note: I m using ListView1.ListItems.Count to increment the Index
'' Use can Also use the PRIMARY KEY , if any, as an Index for the Listview
Set Litem = ListView1.ListItems.Add(ListView1.ListItems.Count + 1, "" & rs![PRIMARY_KEY_FIELD], "" & rs![TEXT_TO_BE DISPLAYED], "Someicon")
Litem.Tag = "" & rs![SOME_ADDITIONAL_INFO]
rs.MoveNext
Loop
End If
'' very Important ;)
rs.Close
Set rs = Nothing
'*****************************************

Hope this is what U wanted.
If not tell me. I wud love to help u.
All the Best

Samuel Roshan


Report Offensive Follow Up For Removal

Response Number 3
Name: irfreh
Date: June 9, 2006 at 02:24:51 Pacific
Reply: (edit)

Thanks guys, that was a great help.


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge
Poll History




Data Recovery Software