Hi, I have a webform with a bunch of dropdown lists that I've filled value from an .mdb table. I'm trying to make a submit button to call an INSERT statement based on the values selected in the dropdown lists.. I've been playing around with the selecteditem and selectedvalue properties but I can't seem to get it to assign the current dropdown selection to a string variable (i'm new to this). Is there any easy way to do this, or something i'm missing ? I've made a test button to display the selecteditem of the dropdown list in a label.. but I can only get it to display the top value of the list, even if I select another value.
'INSERT WEBFORM VALUES INTO UNITS TABLE
Dim objConn As New OleDbConnection(CONNSTRING)
'Create a command object for the query
'Const strSQL6 As String = "INSERT into units (SerialNum, EngineNum, KeyNum, BillofLading, Memo, Model, Color, ModelYear, Assembled, Brand, UnitGroup, UnitStatus, Location, Availability) VALUES vin "
'Const strSQL6 As String = "INSERT into units (SerialNum) VALUES (@add_vin)"
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)"
objCmd6.CommandText = "INSERT into units (SerialNum, EngineNum, Assembled) VALUES (@add_vin, @add_engine, @add_assembled)"
'Create/Populate the DataReader
objCmd6.Parameters.Add("@add_vin", add_vin)
objCmd6.Parameters.Add("@add_engine", add_engine)
'objCmd6.Parameters.Add("@add_key", add_key)
'objCmd6.Parameters.Add("@add_bill", add_bill)
'objCmd6.Parameters.Add("@add_memo", add_memo)
'objCmd6.Parameters.Add("@add_model", add_model)
'objCmd6.Parameters.Add("@add_color", add_color)
'objCmd6.Parameters.Add("@add_year", add_year)
objCmd6.Parameters.Add("@add_assembled", add_assembled)
'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 Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim test As String
test = model.SelectedItem.ToString
Label15.Text = test
End Sub.SelectedValue should return a string.
Where is the code that actually binds the lists??This is the code binding one of the dropdown lists..
'MODEL
objConn.Open()
'Create a command object for the query
Const strSQL1 As String = "SELECT model FROM models ORDER by model"
Dim objCmd1 As New OleDbCommand(strSQL1, objConn)
'Create/Populate the DataReader
Dim objDR1 As OleDbDataReader
objDR1 = objCmd1.ExecuteReader()
model.DataSource = objDR1
model.DataBind()
objConn.Close()
I tried using model.selectedvalue it does return a string, but it will only return the first value in the dropdown list, no matter which value i select. I click the button, the dropdown lists flips back to the first value in the list and my label will only display that first value.
'INSERT WEBFORM VALUES INTO UNITS TABLE
Dim objConn As New OleDbConnection(CONNSTRING)
'Create a command object for the query
'Const strSQL6 As String = "INSERT into units (SerialNum, EngineNum, KeyNum, BillofLading, Memo, Model, Color, ModelYear, Assembled, Brand, UnitGroup, UnitStatus, Location, Availability) VALUES vin "
'Const strSQL6 As String = "INSERT into units (SerialNum) VALUES (@add_vin)"
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)"
objCmd6.CommandText = "INSERT into units (SerialNum, EngineNum, Assembled) VALUES (@add_vin, @add_engine, @add_assembled)"
'Create/Populate the DataReader
objCmd6.Parameters.Add("@add_vin", add_vin)
objCmd6.Parameters.Add("@add_engine", add_engine)
'objCmd6.Parameters.Add("@add_key", add_key)
'objCmd6.Parameters.Add("@add_bill", add_bill)
'objCmd6.Parameters.Add("@add_memo", add_memo)
'objCmd6.Parameters.Add("@add_model", add_model)
'objCmd6.Parameters.Add("@add_color", add_color)
'objCmd6.Parameters.Add("@add_year", add_year)
objCmd6.Parameters.Add("@add_assembled", add_assembled)
'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 Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim test As String
test = model.SelectedItem.ToString
Label15.Text = test
End Sub.SelectedValue should return a string.
Where is the code that actually binds the lists??This is the code binding one of the dropdown lists..
'MODEL
objConn.Open()
'Create a command object for the query
Const strSQL1 As String = "SELECT model FROM models ORDER by model"
Dim objCmd1 As New OleDbCommand(strSQL1, objConn)
'Create/Populate the DataReader
Dim objDR1 As OleDbDataReader
objDR1 = objCmd1.ExecuteReader()
model.DataSource = objDR1
model.DataBind()
objConn.Close()
I tried using model.selectedvalue it does return a string, but it will only return the first value in the dropdown list, no matter which value i select. I click the button, the dropdown lists flips back to the first value in the list and my label will only display that first value.