|
lvData.SelectedItems(0).Index
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I am working with access database and vb.net. I like to make two listBox in a form. first for product list and second for suppliers list of those corresponding products. When I click product list item corresponding suppliers of that product should be show in supplier list.Data retrive from products and suppliers table from database. I am a begainer of programming. Please help me to design the code.
|
|
|
|
|
Hiii
I send a sample of code that use the Access Database (Test.mdb from C and that contain Table1 ( "Prodct" and "Supplier") fields.
Dim myConnection As New OleDbConnection()
dim oDataAdapter as dataAdapter
Dim oDataTable as DataTable
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
myconnection=new oledbconnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Test.Mdb")
oDataAdapter = New OleDbDataAdapter("Select * From Table1", myConnection)
oDataTable=New DataTable
oDataAdapter.Fill(oDataTable)
ListBox1.DataSource = oDataTable
ListBox1.ValueMember = "product"
end sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
dim sProduct as string=ListBox1.SelectedItem.ToString()
if not isNothing (sproduct) then
oDataAdapter = New OleDbDataAdapter("Select Supplier From Table1 where Product=" & sProduct & ", myConnection)
oDataTable=New DataTable
oDataAdapter.Fill(oDataTable)
ListBox2.DataSource = oDataTable
ListBox2.ValueMember = "Supplier"
end if
End Sub
may be it helps you.
Thanx
~Khatri Mitesh
|
|
|
|
|
Hi,
You need to implment the parent-child relationship between the two tables to get the desired results. You may try the following code snippet:
---------------------------------------------------------------------------------------------------
BEGIN CODE
Dim dc As OleDbConnection
Dim connstr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Nwind.mdb;"
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim da As OleDbDataAdapter
Dim dt As DataTable
Dim dv As DataView
dc = New OleDbConnection(connstr)
da = New OleDbDataAdapter("Select * from Products", dc)
dt = New DataTable
da.Fill(dt)
dv = New DataView(dt)
Me.ListBox1.DataSource = dv
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim SupplierIDString = Me.C1Combo1.Columns("SupplierID").Text.ToString()
Dim da As OleDbDataAdapter
Dim dt As DataTable
Dim dv As DataView
dc = New OleDbConnection(connstr)
da = New OleDbDataAdapter("Select * from Supplier where SupplierID = '" + SupplierID+ "'", dc)
dt = New DataTable
da.Fill(dt)
dv = New DataView(dt)
Me.ListBox2.DataSource = dv
End Sub
END CODE
---------------------------------------------------------------------------------------------------
Hope this helps .
Regards,
John Adams
ComponentOne LLC
|
|
|
|
|
When I build my project, the debug version builds fine but the release version does not. No files appear in the Release folder within the bin directory, although, the file path set in the project settings is correct.
Any ideas?
|
|
|
|
|
Are you getting errors when you build in release mode? If so, what errors are you getting?
In the project settings, are you sure you are looking at the Release configuration when checking the build output path?
Without more info, it's hard to know what to suggest. But maybe this will help you think of another option to try.
|
|
|
|
|
Got it, thank you. Problem now sorted. Very silly mistake, so much so that it's embarrassing lol!
Thanks for the help
|
|
|
|
|
hi,
can anyone help me how to make this code little easier
Dim a1,a2,a3,a4,a5,a6,a7 as byte
a1 = Convert.ToByte(ListBox3.Items(0))
a2 = Convert.ToByte(ListBox3.Items(1))
a3 = Convert.ToByte(ListBox3.Items(2))
a4 = Convert.ToByte(ListBox3.Items(3))
a5 = Convert.ToByte(ListBox3.Items(4))
a6 = Convert.ToByte(ListBox3.Items(5))
a7 = Convert.ToByte(ListBox3.Items(6))
i'm now have confusing about array..
please anyone can guide me if have more than 7 statement..
|
|
|
|
|
Make it an array of 7 items, called a, then assign them in a loop.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Arrays are zero based, so the index gets different from your current names:
Dim a(6) as Byte
For i As Integer = 0 to 6
a(i) = Convert.ToByte(ListBox3.Items(i))
Next
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Yeah, I'd have done that, but I was pretty sure my VB would not compile...
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Christian Graus wrote: Yeah, I'd have done that, but I was pretty sure my VB would not compile...
Why do you think that?
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Because if I did it off the top of my head, I don't know VB that well. I am about to 5 you BTW, I can't believe how many good answers get 1 votes now.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I Need to list all the domains and machine in the domains in the network in VB 2.0. does any one has the code
|
|
|
|
|
nitin_ion wrote: in VB 2.0
You've got to be joking right!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Surely he means VB.NET v2. Right?
Steve Jowett
-------------------------
It is offen dangerous to try and see someone else's point of view, without proper training. Douglas Adams (Mostly Harmless)
|
|
|
|
|
I hope... else
Do until "Hell Freezes Over"
Debug.Print("Astonished")
Loop
Kazz
"Users are there to click on things, not think. Let the archs do the damn thinking."
|
|
|
|
|
or
Gosub hades
Hades:
No return
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Sample:
*************************************************
Dim MyCollect as Collection
Set MyCollect = new Collection
Dim Data as Integer
Data = 1
MyCollect.Add Data
Data = 2
MyCollect.Add Data
Data = 3
MyCollect.Add Data
Set MyCollect = Nothing
*************************************************
From the above sample, Collection class object has three item and without remove that item, i just set nothing. The "Set MyCollect = Nothing" statement really remove the item internally or we need to remove externally by iterate item and remove it.
The above sample item is integer data, but my case is that item is an object. So do i need to remove the item (object) from the collection then set nothing?
Sakthivel P.
|
|
|
|
|
It does what it says, sets th whole thing to nothing
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Data is a value type, so you have three ints, not three references to one int. However, there are so many points of confusion here, that your best bet is to buy a book and read it.
Setting a collection to nothing does NOT do anything to the objects in it, it simply gets rid of the object which was maintaining references to the collection.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
That why i'm asking,
Set nothing to collection, it won't free or remove the items of the collection.
|
|
|
|
|
Well, if the collection is the only place a reference to the objects exists, then they are orphaned and will be GC eventually. But, if you have other references to them, then no
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
This collection only the reference to the object. so do i need to remove the item and delete it by external?
|
|
|
|
|
Depends. If they are objects that have a Dispose method, then yes, you should call the Dispose method. If not, what can you do ? you can't delete the objects, this is a GC environment, remember ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|