Click here to Skip to main content
15,891,621 members
Please Sign up or sign in to vote.
1.44/5 (3 votes)
See more:
I have 3tables

agent(brokerid,name,place,date,year)
buyer(id,name)
item(brokerid-forign key,name,place,date,year,lotno,lname,description,amt)

now i have inserted records into item table from form end.

now i have taken 2list box and 1 combobox in another form,

i want to add all the lotno and their respective amt based on combobox selection.

example. 1 single agent id has many lotno and their amt .

so upon combo box selection of agentid,the respective all the lot no and amt will be populated in 2 separate listbox.

can anyone help me plz.

i am new to this.

thanks in advance.
Posted
Updated 13-Aug-13 18:10pm
v2
Comments
Sergey Alexandrovich Kryukov 14-Aug-13 0:05am    
I removed all your comments. Please put the whole question in the body of the question.
First of all, ComboBox — which one? Exact full name of the type, please.
—SA
sudeshna from bangkok 14-Aug-13 0:08am    
sorry the 2nd table is buyer not broker,my typing mistake
sudeshna from bangkok 14-Aug-13 0:09am    
so combo box for brokerid from agent table which is forign key in item table
sudeshna from bangkok 14-Aug-13 0:14am    
Now can you help me plz
sudeshna from bangkok 14-Aug-13 0:38am    
Can anyone help me plz, i m new to it.

Thanks in advance

See Below Updated Code :

VB
Dim cn As New SqlConnection("Data Source=.\INSTANCE;initial catalog=stamp;user=sa;password=gariahat")
        Dim cmd As New SqlCommand
        Dim ds As New DataSet
        Dim dt As DataTable

        cmd.Connection = cn
        cn.Open()

        Dim da As New SqlDataAdapter("select * from item where broker_id = " + ComboBox1.SelectedValue, cn)
        dt = New DataTable

        ds = New DataSet
        da.Fill(ds, "item")

        For Each row As var In ds.Tables("item").Rows
            ListBox1.Items.Add(DirectCast(row, System.Data.DataRow)("lot_no").ToString())
            ListBox2.Items.Add(DirectCast(row, System.Data.DataRow)("amt").ToString())
        Next
 
Share this answer
 
Comments
sudeshna from bangkok 14-Aug-13 3:09am    
what is this var? a variable? an error showing, its saying its not defined
sudeshna from bangkok 14-Aug-13 3:22am    
Hello Sir,can you rectify that error,otherwise i cant run my code and check whether your code working or not
CodeBlack 14-Aug-13 3:26am    
replace 'var' with 'DataRow' as mentioned below :

For Each row As DataRow In ds.Tables("item").Rows
sudeshna from bangkok 14-Aug-13 3:32am    
Showing error in the following line
da.Fill(ds, "item")

Incorrect syntax near '='.
sudeshna from bangkok 14-Aug-13 3:37am    
i changed the combobox1.selecteditem instead of selected value, so now its coming.

but my other text fields are not showing as you have changed the full loop statement
VB
Dim cn As New SqlConnection("Data Source=.\INSTANCE;initial catalog=stamp;user=sa;password=gariahat")
        Dim cmd As New SqlCommand
        Dim ds As New DataSet
        Dim dt As DataTable

        cmd.Connection = cn
        cn.Open()

        Dim da As New SqlDataAdapter("select * from item where broker_id = " + ComboBox1.SelectedItem, cn)
        dt = New DataTable

        ds = New DataSet
        da.Fill(ds, "item")

        Dim sumAmount As Double = 0

        For Each row As DataRow In ds.Tables("item").Rows
            TextBox1.Text = DirectCast(row, System.Data.DataRow)("name").ToString()
            TextBox2.Text = DirectCast(row, System.Data.DataRow)("place").ToString()
            TextBox3.Text = DirectCast(row, System.Data.DataRow)("date").ToString()
            TextBox4.Text = DirectCast(row, System.Data.DataRow)("year").ToString()
            ListBox1.Items.Add(DirectCast(row, System.Data.DataRow)("lot_no").ToString())
            ListBox2.Items.Add(DirectCast(row, System.Data.DataRow)("amt").ToString())

            sumAmount = sumAmount + Convert.ToDouble(DirectCast(row, System.Data.DataRow)("amt"))

        Next

        TextBox6.Text = sumAmount.ToString()
        TextBox7.Text = (0.175 * sumAmount).ToString()

        cn.Close()
 
Share this answer
 
Comments
sudeshna from bangkok 15-Aug-13 23:18pm    
Hello,sorry to bother you again, if i want to add now textbo6 and textbox 7 values and put the value in textbox 8,how do i do it?
i did like this:-
textbox8.text=textbox6.text+textbox7.text

but its just concatinating the values and putting it. its not adding it.
sudeshna from bangkok 15-Aug-13 23:23pm    
i did it myself
sudeshna from bangkok 15-Aug-13 23:24pm    
TextBox6.Text = sumAmount.ToString()
TextBox5.Text = (0.175 * sumAmount).ToString()
TextBox7.Text = (0.07 * TextBox5.Text).ToString()
TextBox9.Text = Val(TextBox5.Text) + Val(TextBox6.Text) + Val(TextBox7.Text)
sudeshna from bangkok 15-Aug-13 23:25pm    
but my textbox 7 which is a vat calculating and textbox 9 which is the actual total calculating.

but both these values after decimal coming 4 places, i want it only decimal 2 places,how do i do it?

the value coming as 1234.6789
but i want it as 1234.68
CodeBlack 16-Aug-13 0:45am    
you can use Math.Round method for that
In selected index changed event, get the selected value (brokerid) of the combobox.

1. now one select query for the lot no :
"select lotno from item where brokerid = [SelectedValue]"

Bind all the lotnos in one list box.

2. another select query for the amount :
"select amt from item where brokerid = [SelectedValue]"

Bind all the amounts in another list box.
 
Share this answer
 
v2
Comments
sudeshna from bangkok 14-Aug-13 1:28am    
but how can i bind all of them, as it is stored in database and will come in runtime from database.
sudeshna from bangkok 14-Aug-13 1:29am    
this is what i have done,my code but list box is not getting populated upon combobox selection
sudeshna from bangkok 14-Aug-13 1:39am    
can you give me the code,i cant understand. i have binded the data.
then next what do i do? i am new to this concept
sudeshna from bangkok 14-Aug-13 1:40am    
i have given my code in solution, what i have done
VB
Dim cn As New SqlConnection("Data Source=.\INSTANCE;initial catalog=stamp;user=sa;password=gariahat")
        'Dim da As New SqlDataAdapter
        Dim cmd As New SqlCommand
        Dim ds As New DataSet
        Dim dt As DataTable


        'Try

        cmd.Connection = cn
        cn.Open()

        Dim da As New SqlDataAdapter("select * from item", cn)
        dt = New DataTable

        ds = New DataSet
        da.Fill(ds, "item")

        For i As Integer = 0 To ds.Tables("item").Rows.Count - 1
            If ComboBox1.SelectedItem = ds.Tables("item").Rows(i).Item("broker_id").ToString() Then
                TextBox1.Text = ds.Tables("item").Rows(i).Item("name").ToString()
                TextBox2.Text = ds.Tables("item").Rows(i).Item("place").ToString()
                TextBox3.Text = ds.Tables("item").Rows(i).Item("date").ToString()
                TextBox4.Text = ds.Tables("item").Rows(i).Item("year").ToString()
                ListBox1.Text = ds.Tables("item").Rows(i).Item("lot_no").ToString()
                ListBox2.Text = ds.Tables("item").Rows(i).Item("amt").ToString()



            End If

        Next


        cn.Close()
 
Share this answer
 
Comments
sudeshna from bangkok 15-Aug-13 6:47am    
Thank u very much.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900