inserting parameters from a drop-down list.

I am trying to insert a bunch of parameters into an access table.. about half are textboxes (which work fine now), and the others are from a dropdown list which I've filled with data from another table. Currently it will only insert the first value that is in the dropdown list, regardless of what I have selected. The only thing i can think of is it may have something to do with the postback property (which i'm not too familiar with since I'm somewhat new to this).. can someone take a look at my code and see if I'm missing something. (my INSERT string isn't complete in this code only because i've been screwing around with it to try and fix this problem) Thanks.

Another question i had is, does it matter which order I add the parameters in? ie. should i follow the same structure as they are listed in the mdb table?


Private Sub Add_Unit_Btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Add_Unit_Btn.Click
Dim add_vin As String
Dim add_engine As String
Dim add_key As String
Dim add_bill As String
Dim add_memo As String
Dim add_model As String
Dim add_color As String
Dim add_year As String
Dim add_assembled As Boolean
Dim add_brand As String
Dim add_type As String
Dim add_status As String
Dim add_location As String
Dim add_availability As String



add_vin = vin.Text
add_engine = engine.Text
add_key = key.Text
add_bill = lading.Text
add_memo = memotext.Text
add_assembled = assembled.Checked
add_model = model.SelectedItem.Text
add_color = color.SelectedValue
add_year = year.Text
add_brand = brand.SelectedValue
add_type = group.SelectedValue
add_status = status.SelectedValue
add_location = location.SelectedValue
add_availability = availability.SelectedValue


'INSERT WEBFORM VALUES INTO UNITS TABLE
Dim objConn As New OleDbConnection(CONNSTRING)


Dim objCmd6 As New OleDbCommand("", objConn)
'objCmd6.CommandText = "INSERT into units (SerialNum, EngineNum, KeyNum, BillofLading, Memo, Model, Color, ModelYear, Assembled, Brand, UnitGroup, UnitStatus, Location, Availability) VALUES (@add_vin, @add_engine, @add_key, @add_bill, @add_memo, @add_model, @add_color, @add_year, @add_assembled, @add_brand, @add_type, @add_status, @add_location, @add_availability)"
' OLD SQL STRING /// objCmd6.CommandText = "INSERT into units (ModelYear, Assembled, Memo, SerialNum, EngineNum, KeyNum) VALUES (@add_year, @add_assembled, @add_memo, @add_vin, @add_engine, @add_key)"

'Create/Populate the DataReader
objCmd6.CommandText = "INSERT into units (Memo) VALUES (@add_memo)"

'TEXT BOXES
objCmd6.Parameters.Add("@add_year", add_year)
objCmd6.Parameters.Add("@add_assembled", add_assembled)
objCmd6.Parameters.Add("@add_bill", add_bill)
objCmd6.Parameters.Add("@add_memo", add_memo)
objCmd6.Parameters.Add("@add_vin", add_vin)
objCmd6.Parameters.Add("@add_engine", add_engine)
objCmd6.Parameters.Add("@add_key", add_key)

'DROPDOWN LISTS
objCmd6.Parameters.Add("@add_model", add_model)
objCmd6.Parameters.Add("@add_color", add_color)
objCmd6.Parameters.Add("@add_brand", add_brand)
objCmd6.Parameters.Add("@add_type", add_type)
objCmd6.Parameters.Add("@add_status", add_status)
objCmd6.Parameters.Add("@add_location", add_location)
objCmd6.Parameters.Add("@add_availability", add_availability)

objCmd6.CommandType = CommandType.Text
objConn.Open()
objCmd6.ExecuteNonQuery()
objConn.Close()

End SubEwwww... I have run into this myself. I just said forget it and just wrote out a list of links with query strings one time because I did not want to fool with it, but there is a way to fix this. I will look for the solution tomorrow.Thanks PeOfEo, I've been trying to figure this out for soo long.. and I can't really do what you suggested because one of my dropdown lists contains about 800 model names, so manually writing out query strings is kinda out of the question..The way I did it was not manual, I wrote the query strings out from data with a repeater. But look at this article, I think the way they are doing it should work, at the end is a nifty little work around
<!-- m --><a class="postlink" href="http://www.4guysfromrolla.com/webtech/071101-1.shtml">http://www.4guysfromrolla.com/webtech/071101-1.shtml</a><!-- m -->
 
Back
Top