i have made a database in sql+. it has a database. there is a table project. its columns are p_id,p_name,p_manager.

i have inserted 5 rows in above table.

in d front end in vb6 i have a form . please help me with the code such that my p_id is a combobox. wen i select my p_id then the corresponding p_name and P_manager should be displayed in text box on the form. please help!

thank you!

Recommended Answers

All 5 Replies

'Try this code


con.open

sql = "SELECT * FROM YOUR TABLE WHERE P_ID = " & YourTextBox & "
cmd = New oledb.oledbcommand(sql,con) 'cmd = command. con = connection
dr = cmd.executereader  'This would be your data reader

while dr.read
    textboxPName = dr("p_name")
    textboxPManager = dr("p_manager")
end while

con.close

i think you'll need put that code into index change event for combo

i currently enter p_id through sql query into the database.
this is the code i use to enter values into project.

con.Execute "insert into project values (" + Text1.Text + ",'" + Text2.Text + "','" + Text3.Text + "')"
MsgBox "Project Added Successfully!!"
Text1.Text = ""                          'for id
Text2.Text = ""                          'for name
Text3.Text = ""                          'for manager

how do i get the values of p_id into my combo box?

ok. if you want to put all the ID in the combobox.

put this into your Form Load Event.

Con.open
sql = "SELECT p_id FROM YOURTABLE"
cmd = New Oledb.OledbCommand(sql,con)
dr = cmd.executereader

while dr.read
    Combobox.items.add(dr("p_id"))
end while

con.close

the following line is shown in red

cmd = New Oledb.OledbCommand(sql,con)

please note i use adodb connection in vb 6.0 tp connect to sql database. how do i correct it?

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.