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

combobox and textbox

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.

kritiohri
Newbie Poster
24 posts since Nov 2008
Reputation Points: 10
Solved Threads: 0
 

Hi,

it should be easy;

show me your codes;

good luck;

Bandar.M.A
Newbie Poster
18 posts since Feb 2009
Reputation Points: 10
Solved Threads: 1
 

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.

kritiohri
Newbie Poster
24 posts since Nov 2008
Reputation Points: 10
Solved Threads: 0
 

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

Bandar.M.A
Newbie Poster
18 posts since Feb 2009
Reputation Points: 10
Solved Threads: 1
 

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

jbrock31
Junior Poster in Training
79 posts since Oct 2008
Reputation Points: 22
Solved Threads: 16
 

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 complicatedWHEN 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. ;)

jireh
Posting Whiz
316 posts since Jul 2007
Reputation Points: 11
Solved Threads: 49
 

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

Private sub Combobox1_selectedindexchanged(byval sender As System.object, ByVal e as system.eventargs) Handles Combobox1.Selectedindexchanged
'(declare con as connection)
Dim Da as New OledbDataAdapter
Dim Ds As New Dataset
Dim Dt As DataTable
Try
Da=New OledbDataAdapter("Select * from Tablename where DeptName="& Combobox1.SelectedItem & "",Con)
Da.fill(Ds, "TableName")
Dt = Ds.Tables("TableName")
Catch ex As Exception
Messagebox.show(ex.Message)
End Try
Textbox1.Text = Dt.Rows.Item(0).Item(0)
End sub
Praniya
Newbie Poster
3 posts since Feb 2009
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You