Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting Records from a dropdown list 1

Status
Not open for further replies.

dvannoy

MIS
May 4, 2001
2,765
US
I have a dropdown list that gets it data from an access table. I then want the user to select what they want in the list(works fine) OK, now I am trying to insert data from the form including the dropdown list into another table. since the dropdown list has no .Text property what should i use to make this happen..

I have tryed DataTextField, DataValueField and that does not work..

Can someone help with this?

Thanks
 
"yourDropDownList.SelectedItem.Value"
 
I tryed that and all i get is the field name inserted..heres my code to bind the dropdown list

Public strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("BD.mdb") & ";"

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim Conn As New OleDbConnection(strConn)
Dim strSQL As String = "SELECT Componet FROM table"
Dim cmd As New OleDbCommand(strSQL, Conn)

Conn.Open()

cboProduct1.DataSource = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
cboProduct1.DataTextField = "Componet"
cboProduct1.DataValueField = "Componet"
cboProduct1.DataBind()


then I am doing a simepl SQL insert command into the DB..

I can see the correct fields inside the dropdown list but it inserts the field name into the field of the DB rather then the item selected..


Thanks
 
What do you mean 'field name'? The field name in the table you pulling from, or the field name in the table you are inserting into? Please give more detail.
 
The field name in the database is componet.. thats what gets written back to the DB.. so, my dropdown list may contain componet names such as OIL, FUEL etc.. if i choose OIL from the list and then write back to the Database, it wont write the word OIL but instead writes the word componet.
 
Do you set 'Componet' as o-index item(On the top of your dropdownlist)? If so, try use 'Not IsPostBack' to make sure you only load your dropdownlist once.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top