Question listbox items in form 1 to show on textboxes in form2

Sythe

Member
Joined
Jul 18, 2012
Messages
13
Programming Experience
Beginner
How do you show on textboxes in Form2 the items on listbox in form1. Like i have a "123" data on listbox1 (Form1) then i need to check that if it matches in my database, and if it does, on form2 textboxes, it will display additional information of that from database.


VB.NET:
Form1
    Private Sub listBox3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles listBox3.SelectedIndexChanged
        Form2.TextBox6.Text = listBox3.GetItemText(listBox3.SelectedItem)


        If listBox3.GetItemText(listBox3.SelectedItem) = "09 00 EE 00 1F 4F 30 00 75 E0 " Then
            MsgBox("SUCCESS")
            'Me.Hide()
            Form2.Show()
        Else
            MsgBox("FAIL")
        End If
    End Sub


VB.NET:
Form2
        connstring = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Csrp2_DB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
        conn.ConnectionString = connstring


        If TextBox6.Text = "09 00 EE 00 1F 4F 30 00 75 E0 " Then
            sql = "SELECT * from Csrp2_table1 Where Title='" & UCase(TextBox1.Text) & "'" + _
                ",Author='" & UCase(TextBox2.Text) & "'" + _
                ",Price='" & UCase(TextBox3.Text) & "'" + _
                ",Stock='" & UCase(TextBox4.Text) & "')"
            Else
            MsgBox("FAIL")
        End If
 
Another problem :s can you guys please tell me whats wrong on my code. Im trying to get the data of Title, Author, Price, Stock from DB and output it on my textboxes.


VB.NET:
    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load




        connstring = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Csrp2_DB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
        conn.ConnectionString = connstring






        If TextBox6.Text = form1.TextBox6.Text Then
            sql = "SELECT from Csrp2_table1 (Title, Author, Price, Stock) Values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "')"


            MsgBox("BZZ")
        Else
            MsgBox("FAILs")
        End If




        Dim da As New SqlDataAdapter(sql, conn)


        conn.Open()
        da.Fill(ds)
        conn.Close()
    End Sub




Or do you guys think im missing this code
VB.NET:
" WHERE RFID = '" textbox6.text " ' "


but where should i put it???
 
i got it to work. My select command on that is so wrong should be like this
("SELECT Summary FROM Csrp2_table1 WHERE RFID = '" & TextBox6.Text & "' ", conn)

then some if and bla bla bla.
thanks though.
 
Back
Top