954,535 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

To display data in textbox and label

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

Es Sayen
Newbie Poster
19 posts since Jun 2007
Reputation Points: 10
Solved Threads: 0
 

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

QVeen72
Posting Shark
950 posts since Nov 2006
Reputation Points: 84
Solved Threads: 143
 

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.

Es Sayen
Newbie Poster
19 posts since Jun 2007
Reputation Points: 10
Solved Threads: 0
 

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

QVeen72
Posting Shark
950 posts since Nov 2006
Reputation Points: 84
Solved Threads: 143
 

Thank you Veena.

It worked.

Es Sayen
Newbie Poster
19 posts since Jun 2007
Reputation Points: 10
Solved Threads: 0
 

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....

snta
Newbie Poster
8 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

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

QVeen72
Posting Shark
950 posts since Nov 2006
Reputation Points: 84
Solved Threads: 143
 

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

abdalla_92
Newbie Poster
7 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You