hello,

when user slect an item from combobox, then its corresponding data should be displayed in the textboxes and labels placed on the form.
like if i select a rollno then the name, address, age should appear on the form.

kindly, let me know the code for this.

Thanks in advancce

Hi,
Write This Code In Lost_Focus event of ComboBox:(Conn-> Connection object)

DIm RST As New ADODB.RecordSet
Dim sSQL As String

sSQL = "Select * From MyTable Where RollNo = " & Val(Combo1.Text)
RST.Open sSQL, Conn
If Not RSt.EOF Then
txtName.Text = RST("Name")
txtAdd.Text = RST("Addr")
txtAge.Text = RST("Age")
Else
txtName.Text = ""
txtAdd.Text = ""
txtAge.Text = ""
End If
RST.Close
Set RST=Nothing

REgards
Veena

hello veena,

Thanks for your reply.

I am using this code on combo box click event and it is giving error and when i used it on lost focus event even then it is giving err that the operation could not be performed.

Hi,

RollNo Is Numeric or Text..?

If it is text then use this SQL:

sSQL = "Select * From MyTable Where RollNo = '" & trim(Combo1.Text) & "'"

REgards
Veena

Thank you Veena.

It worked.

my function same like u,but why my textbox can't display data..
my entire coding is like that:
Private Sub cboItem_LostFocus()

Dim rst As New ADODB.Recordset
Dim sql As String

sql = "select ItemID,ItemName from Item where ItemID='" & Val(cboItem.Text) & "'"
rst.Open sql, conn

If Not rst.EOF Then
Text1.Text = rst("ItemName")
Else
Text1.Text = ""
End If
rst.Close
Set rst = Nothing
End Sub

Private Sub form_Load()
cboItem.AddItem "C1", 0
cboItem.AddItem "M1"
connect
End Sub

plzz help me....

Hi Snta,

Start a New Thread...
Any way, Change Your SQL Statement to :

sql = "select ItemID,ItemName from Item where ItemID='" & Trim(cboItem.Text) & "'"

Replace Val() with Trim()

REgards
Veena

hello,
when iselect an item from combobox, then its corresponding data should be displayed in the textboxes and placed on the form.
like if i select a vendor combo box then the vendor name, vendor address, vendor product should appear on the form.
NB: Iam using vb.net2005 and mssql2005

kindly, let me know the code for this.

Thanks in advancce

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.