combobox and textbox

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2008
Posts: 24
Reputation: kritiohri is an unknown quantity at this point 
Solved Threads: 0
kritiohri kritiohri is offline Offline
Newbie Poster

combobox and textbox

 
0
  #1
Feb 25th, 2009
I have a sql table consisting of dept_name and dept_code.and on the form i have textbox for dept_code and combobox for dept_name.When i select a particular dept_name from the combobox i should get the corrosponding dept_code in the textbox.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 18
Reputation: Bandar.M.A is an unknown quantity at this point 
Solved Threads: 1
Bandar.M.A Bandar.M.A is offline Offline
Newbie Poster

Re: combobox and textbox

 
0
  #2
Feb 25th, 2009
Hi,

it should be easy;

show me your codes;

good luck;
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 24
Reputation: kritiohri is an unknown quantity at this point 
Solved Threads: 0
kritiohri kritiohri is offline Offline
Newbie Poster

Re: combobox and textbox

 
0
  #3
Feb 25th, 2009
I dont have the code .The combox contains the dept_names and i want the cprrosponding value that is the dept_no in the yextbox.iam able to save the values.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 18
Reputation: Bandar.M.A is an unknown quantity at this point 
Solved Threads: 1
Bandar.M.A Bandar.M.A is offline Offline
Newbie Poster

Re: combobox and textbox

 
0
  #4
Feb 25th, 2009
Ok

in Combobox event changeindex (or something like that)
try to send Sql statement with the value you get then
put the result in your textbox
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 29
Reputation: jbrock31 is an unknown quantity at this point 
Solved Threads: 1
jbrock31 jbrock31 is offline Offline
Light Poster

Re: combobox and textbox

 
0
  #5
Feb 25th, 2009
use data binding.

There are many guides or examples on this, but i googled and this is the first result i got.

http://www.startvbdotnet.com/ado/Simplebinding.aspx
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 300
Reputation: jireh is an unknown quantity at this point 
Solved Threads: 42
jireh's Avatar
jireh jireh is offline Offline
Posting Whiz

Re: combobox and textbox

 
0
  #6
Feb 25th, 2009
first is what field is your primary key? is it the dept_code or dept_name?

When i select a particular dept_name from the combobox i should get the corrosponding dept_code in the textbox.
Now, what you want is a little bit complicated WHEN your primary is the dept_code.

Why? because if your primary is dept_code then it is very possible that there will be the same department name but have different code. right? so ergo, if you are going to select a department name the department code to be return will be the first department code saved in the database, thus you are not sure that the department code you are looking is the correct one.

regards.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3
Reputation: Praniya is an unknown quantity at this point 
Solved Threads: 1
Praniya Praniya is offline Offline
Newbie Poster

Re: combobox and textbox

 
0
  #7
Feb 27th, 2009
Hello,
I am Not as good as all of you but i tried with this, and i am agree with jireh.

And After I try i am at following :-

First Declare Con as Connection
  1. Private sub Combobox1_selectedindexchanged(byval sender As System.object, ByVal e as system.eventargs) Handles Combobox1.Selectedindexchanged
  2. '(declare con as connection)
  3. Dim Da as New OledbDataAdapter
  4. Dim Ds As New Dataset
  5. Dim Dt As DataTable
  6. Try
  7. Da=New OledbDataAdapter("Select * from Tablename where DeptName="& Combobox1.SelectedItem & "",Con)
  8. Da.fill(Ds, "TableName")
  9. Dt = Ds.Tables("TableName")
  10. Catch ex As Exception
  11. Messagebox.show(ex.Message)
  12. End Try
  13. Textbox1.Text = Dt.Rows.Item(0).Item(0)
  14. End sub
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC