473,396 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how do i search a value using combo box in vb.net

i am using dotnet 2003.i am doing my project in vb.net windows application.i have two form in my project.first form is datagrid .In second form label,textboxes and combobox are avilable to save the entering values in datagrid of first form through this 2nd form.my problem is,i want to search a value using combobox.
for example,
in first form,
there are 4 columns named as name,age,rollno,address in datagrid.
values are ramu for namecolumn,24 for age column,42 for rollno column,cbe for address column.now values in datagrid like below
id name age rollno address
1 ramu 24 42 cbe
2 somu 23 32 che
here id is primary key.
in 2nd form,there are 4 label,4 textbox and 1 combobox.textbox arenamed as nametextbox,agetextbox,rollnotextbox,addresstextbo x and 1 combobox named as searchcombobox.
now values of name(ramu,somu) are stored in combobox.
my problem is,
in second form,
if i click the value ramu in combobox means,want to display the values of ramu in textboxes.(ie..want to display automatically ramu in nametextbox,24 in age textbox,42 in rollnotextbox,cbe in address textbox)
during runtime in vb.net windows application.so how i automatically display the values of row in each textbox by clicking the values in combobox.plz help me.
Jun 21 '07 #1
1 6723
dip_developer
648 Expert 512MB
i am using dotnet 2003.i am doing my project in vb.net windows application.i have two form in my project.first form is datagrid .In second form label,textboxes and combobox are avilable to save the entering values in datagrid of first form through this 2nd form.my problem is,i want to search a value using combobox.
for example,
in first form,
there are 4 columns named as name,age,rollno,address in datagrid.
values are ramu for namecolumn,24 for age column,42 for rollno column,cbe for address column.now values in datagrid like below
id name age rollno address
1 ramu 24 42 cbe
2 somu 23 32 che
here id is primary key.
in 2nd form,there are 4 label,4 textbox and 1 combobox.textbox arenamed as nametextbox,agetextbox,rollnotextbox,addresstextbo x and 1 combobox named as searchcombobox.
now values of name(ramu,somu) are stored in combobox.
my problem is,
in second form,
if i click the value ramu in combobox means,want to display the values of ramu in textboxes.(ie..want to display automatically ramu in nametextbox,24 in age textbox,42 in rollnotextbox,cbe in address textbox)
during runtime in vb.net windows application.so how i automatically display the values of row in each textbox by clicking the values in combobox.plz help me.
I think you have these records in database.........
then bind the combobox with name and id.

populate a Dataset(say dsStudent ) with this sql query.....
SELECT id,name FROM mytable

then set the ValueMember and DisplayMember property of combobox like this
Expand|Select|Wrap|Line Numbers
  1.  
  2. searchcombobox.DataSource=dsStudent 
  3. ' Suppose dsStudent is the DataSet name
  4. searchcombobox.ValueMember ="id"
  5. searchcombobox.DisplayMember ="name"
  6.  
In the SelectedIndexChanged of the combobox retrieve the id and execute a sql statement like this...

Expand|Select|Wrap|Line Numbers
  1.  
  2. dim student_id as string 
  3. dim sql as string
  4. student_id = CType(searchcombobox.SelectedItem, DataRowView).Row("id")
  5. sql ="SELECT name,age,rollno,address FROM mytable WHERE
  6. id='" & student_id & "'"
  7.  
with the above sql populate a dataset(say dsSingleRecord)

Now bind the dataset(dsSingleRecord) with 4 textboxes like

Expand|Select|Wrap|Line Numbers
  1.  nametextbox.Text=dsSingleRecord.Tables(0).Rows(0).Item(0) 
  2. agetextbox.Text=dsSingleRecord.Tables(0).Rows(0).Item(1)
  3. rollnotextbox.Text=dsSingleRecord.Tables(0).Rows(0).Item(2)
  4. addresstextbox .Text=dsSingleRecord.Tables(0).Rows(0).Item(3)
  5.  
Jun 21 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: amoona | last post by:
Hi… I’m doing a search page form my work for their library. Since this is the first time I work with ASP I’m facing some problems. Each library item has different search data, I was able to...
9
by: Christopher Koh | last post by:
I will make a form which will search the database (just like google interface) that will look/match for the exact name in the records of a given fieldname. Any suggestions on how to make the code?
4
by: Lauren Wilson | last post by:
A2K I have a combo box that shows the content of a last name field from a table. I use it to locate records in the table form. I can open the form and locate several names quickly by placing...
8
by: Steph | last post by:
Hi. I'm very new to MS Access and have been presented with an Access database of contacts by my employer. I am trying to redesign the main form of the database so that a button entitled...
1
by: dskillingstad | last post by:
Would appreciate any help I could get I have an unbound search form with various text boxes on it for searching my database. I would like to have a combo box on the search form where the source...
4
by: DavidB | last post by:
OK folks I am having a serious brain fart here and can't get the code to do what I really want done. I have a form that has a multi-table query as its data source. The data is dsplayed on the...
0
by: imwhiteandnerdy | last post by:
i'm kinda a newbie I would appreciate some help Basically i'm setting up a search page using multiple options from a combo box Combo Box(2 options) First Name Last Name text box to the...
5
by: mforema | last post by:
Hi Everyone, I want to search records by typing in multiple keywords. I currently have a search form. It has a combo box, text box, Search command button, and a subform. The combo box lists the...
3
by: suek | last post by:
I have a table with over 4000 records to search upon, and the users don't like a combo box. So what I have been trying to do for the last twelve hours is do some code to get a text box to search. ...
1
by: hottoku | last post by:
Hi All, I'm having quite a bit of trouble designing a search tool to work with my database. I have found lots of examples from Microsoft Templates to Allen Browne's sample search form. The...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.