| | |
Getting Supplier detail using listview
![]() |
•
•
Join Date: Dec 2008
Posts: 292
Reputation:
Solved Threads: 1
Can anybody tell me why these statement is not working ?. I want to see supplier detail using listview.here is the code what i have written.
Private Sub Form_Load()
Set con = New ADODB.Connection
con.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=\\asfserver\itp$\Product_tabletest.mdb")
con.CursorLocation = adUseClient
Dim listitem As listitem
ListView1.View = lvwReport
ListView1.ColumnHeaders.Add , , "Supplier No."
ListView1.ColumnHeaders.Add , , "Supplier Name"
ListView1.ColumnHeaders.Add , , "Contact Person"
StrSql = "Select"
StrSql = StrSql & "[supplier_name],[type],[fax_no],[contact_person]"
StrSql = StrSql & "From [Supplier]"
rs.Open StrSql, con, adOpenDynamic, adLockOptimistic
While (Not (rs.EOF))
Set listitem = ListView1.ListItems.Add(suppliername)
listitem.SubItems(1) = IIf(IsNull(rs!supplier_name), "", rs!supplier_name)
listitem.SubItems(2) = IIf(IsNull(rs!Type), "", rs!Type)
listitem.SubItems(3) = IIf(IsNull(rs!fax_no), "", rs!fax_no)
listitem.SubItems(4) = IIf(IsNull(rs!contact_person), "", rs!contact_person)
Wend
End Sub Last edited by firoz.raj; Feb 10th, 2009 at 2:37 am.
your code has some problems that I noticed....anyways this code can be improved...but could you explain what is happening actually when you running this?
what's d error msg you are getting....what's the output coming?
regards
Shouvik
what's d error msg you are getting....what's the output coming?
regards
Shouvik
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Have a problem? Don't worry just give me a call and I'll fix it for you.
Well it's very clear as the sunshine. You have just used the "rs" but not declaring/setting it.
A conclusion is the place where you got tired of thinking. http://www.martin2k.co.uk/forums/index.php?showforum=4
http://www.a1vbcode.com/a1vbcode/vbforums/Forum3-1.aspx
http://www.developerfusion.co.uk/for...orum&ForumID=4
•
•
Join Date: Dec 2008
Posts: 292
Reputation:
Solved Threads: 1
Now i got invalid use of null value.when i uncomment the follwing
line get invalid property value.
here is the code :
line get invalid property value.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
' listitem.SubItems(3) = IIf(IsNull(rs!fax_no), "", rs!fax_no)
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim listitem As listitem
Private Sub Form_Load()
Set con = New ADODB.Connection
con.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=\\asfserver\itp$\Product_tabletest.mdb")
con.CursorLocation = adUseClient
ListView1.View = lvwReport
ListView1.ColumnHeaders.Add , , "Supplier No."
ListView1.ColumnHeaders.Add , , "Supplier Name"
ListView1.ColumnHeaders.Add , , "Contact Person"
StrSql = "Select"
StrSql = StrSql & "[supplier_name],[type],[fax_no],[contact_person] from [Supplier]"
Set rs = New ADODB.Recordset
rs.Open StrSql, con, adOpenDynamic, adLockOptimistic
While (Not rs.EOF)
Set listitem = ListView1.ListItems.Add(, , , supplier_name)
listitem.SubItems(1) = rs!supplier_name
listitem.SubItems(2) = rs!Type
' listitem.SubItems(3) = IIf(IsNull(rs!fax_no), "", rs!fax_no)
listitem.SubItems(3) = rs!fax_no
listitem.SubItems(4) = rs!contact_person
Wend
End Sub Last edited by firoz.raj; Feb 11th, 2009 at 2:03 am.
hi....here is the modified code...just check this out....look for the BOLDED lines....these are where i made some changes....watch GREEN lines for comments....
the problem is within your listview manipulation code.....means when you are adding listitems.....you have mismatched total no. of columns and listitems.....total no. of columns in the listview should match with total no. of listitems you want to add....the problem is you adding 5 listitems to the control where you are having only 3 columns....so that's why the error is coming....
just follow this code and hope you will solve ur problem...
Hope this helps.....please make a feedback here...
regards
Shouvik
the problem is within your listview manipulation code.....means when you are adding listitems.....you have mismatched total no. of columns and listitems.....total no. of columns in the listview should match with total no. of listitems you want to add....the problem is you adding 5 listitems to the control where you are having only 3 columns....so that's why the error is coming....
just follow this code and hope you will solve ur problem...
Dim con As ADODB.Connection Dim rs As ADODB.Recordset Dim listitem As listitem this is for adding the columns to the lv control Dim colx As Columnheader this is for measuring column widths Dim colWidth As Double Private Sub Form_Load() Set con = New ADODB.Connection con.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=\\asfserver\itp$\Product_tabletest.mdb") Set rs = New ADODB.Recordset rs.CursorLocation = adUseClient rs.CursorType = adOpenDynamic rs.LockType = adLockOptimistic StrSql = "Select" StrSql = StrSql & "[supplier_name],[type],[fax_no],[contact_person] from [Supplier]" rs.Open StrSql, con ListView1.View = lvwReport checking the width of listview control and divided by 5...so that all columns become of same width...here we used 5 because the control will have 5 columns colWidth = ListView1.Width / 5 here we are adding the columns you need similar no. of columns as much no. of listitems you want to add to the listview. now if you want to hide any column from displaying, just set its width to 0. With ListView1 .ColumnHeaders.Clear Set colx = .ColumnHeaders.ADD(, , ("Supplier No"), colWidth) Set colx = .ColumnHeaders.ADD(, , ("Supplier Name"), colWidth) Set colx = .ColumnHeaders.ADD(, , ("Type"), colWidth) Set colx = .ColumnHeaders.ADD(, , ("Fax No"), colWidth) Set colx = .ColumnHeaders.ADD(, , ("Contact Person"), colWidth) End With adding rows to listview With ListView1 .ListItems.Clear If rs.RecordCount > 0 Then rs.MoveFirst While Not rs.EOF() Set listitem = .ListItems.ADD(, , (supplier_no)) listitem.SubItems(1) = rs!supplier_name listitem.SubItems(2) = rs!Type listitem.SubItems(3) = IIf(IsNull(rs!fax_no), "", rs!fax_no) listitem.SubItems(4) = rs!contact_person rs.MoveNext Wend End If End With closing the recordset so the memory can be utilized again and also releasing its current instance from the memory If rs.state = adStateOpen Then rs.Close Set rs = Nothing End Sub
Hope this helps.....please make a feedback here...
regards
Shouvik
Last edited by choudhuryshouvi; Feb 11th, 2009 at 4:25 am.
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Have a problem? Don't worry just give me a call and I'll fix it for you.
Last edited by choudhuryshouvi; Feb 11th, 2009 at 4:32 am.
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Have a problem? Don't worry just give me a call and I'll fix it for you.
•
•
Join Date: Dec 2008
Posts: 292
Reputation:
Solved Threads: 1
Now i got item cannot be found in the collection corresponding to the requested name or ordinal.kindly help me anybody.
With ListView1
.ListItems.Clear
If rs.RecordCount > 0 Then
rs.MoveFirst
While Not rs.EOF()
Set listitem = .ListItems.Add(, , (supplier_no))
' listitem.SubItems(1) = rs!supplier_name
listitem.SubItems(1) = IIf(IsNull(rs!supplier_name), "", rs!supplier!Name)
listitem.SubItems(3) = IIf(IsNull(rs_Type), "", rs!Type)
listitem.SubItems(3) = IIf(IsNull(rs_fax_no), "", rs!fax_no)
listitem.SubItems(4) = IIf(IsNull(rs!contact_person), "", rs!contact_person)
' listitem.SubItems(4) = rs!contact_person
rs.MoveNext
Wend
End If
End With Last edited by firoz.raj; Feb 11th, 2009 at 7:12 am.
item cannot be found in the collection corresponding to the requested name or ordinal --> this means you donot have a column with name "supplier_name" in the table...
check the sql statement...whether you are opening the correct table or not...
the table must have the column "supplier_name" in it....
for better observation please upload your full code here....
regards
Shouvik
check the sql statement...whether you are opening the correct table or not...
the table must have the column "supplier_name" in it....
for better observation please upload your full code here....
regards
Shouvik
Last edited by choudhuryshouvi; Feb 11th, 2009 at 7:24 am.
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Have a problem? Don't worry just give me a call and I'll fix it for you.
![]() |
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: vb 6-ocacle on linux connectivity
- Next Thread: timer
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





