3 Replies - 889 Views - Last Post: 17 August 2012 - 07:37 PM Rate Topic: -----

#1 Sythez  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 18-July 12

Problem - Listbox items in form1 to show on textboxes in form2

Posted 17 August 2012 - 09:01 AM

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.


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



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


Is This A Good Question/Topic? 0
  • +

Replies To: Problem - Listbox items in form1 to show on textboxes in form2

#2 b2.f2  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 76
  • Joined: 21-May 07

Re: Problem - Listbox items in form1 to show on textboxes in form2

Posted 17 August 2012 - 09:51 AM

you do it like this:

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim f2 As New Form2
        If ListBox1.SelectedIndex = f2.TextBox1.Text Then
            MsgBox("Go on this website and learn vb.net: http://howtostartprogramming.com/vb-net/")
        End If
    End Sub


This post has been edited by b2.f2: 17 August 2012 - 09:52 AM

Was This Post Helpful? 0
  • +
  • -

#3 Sythez  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 18-July 12

Re: Problem - Listbox items in form1 to show on textboxes in form2

Posted 17 August 2012 - 06:01 PM

Hey thanks for that, and i got another problem. Can you 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.

    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
" WHERE RFID = '" textbox6.text " ' " 


but where should i put it???
Was This Post Helpful? 0
  • +
  • -

#4 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 966
  • View blog
  • Posts: 3,721
  • Joined: 02-July 08

Re: Problem - Listbox items in form1 to show on textboxes in form2

Posted 17 August 2012 - 07:37 PM

A great sql site! It's just a matter of syntax.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1