Hi.. how to get the state_id from the tab_states table. i am selecting the state_name from dropdown list and i have to insert the corresponding State_id value to a tab_city table. i am getting the state_name in drop down list. but while saving it is not taking the state_id..
i am a beginner. so can u please help me to do that coding??? i will give the description of my work.
state name -> i am selecting from a tab_states table(dropdow list)
city name -> i am entering to a textbox.
while saving it should save the state_id of corresponding state_name and city_name to tab_city table.
tab_states table description
state_id
state_name
tab_city table description
city_id
city_name
State_id
The coding which i have done is given below
Dim ds As New DataSet
Dim stateid As New Integer
con.ConnectionString = "Driver={Microsoft ODBC for Oracle};server=dbserver;uid=kms;pwd=kms"
adp = New OdbcDataAdapter("Select State_Id, State_Name from tab_states", con)
ds = New DataSet
adp.Fill(ds)
DListState.DataSource = ds.Tables(0)
DListState.DataTextField = "State_Name"
DListState.DataValueField = "State_Id"
DListState.DataBind()
con.Open()
Private Sub cmd_Add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_Add.Click
Dim stateid As Integer
Dim Query As String
cmd.Connection = con
If txtCityName.Text = "" Then
MessageBox("Fied can not be null")
End If
If txtCityName.Text <> "" Then
'MessageBox(DListState.SelectedItem.ToString())
cmd.CommandText = "insert into tab_City(city_id,city_name,state_id)values(SEQ_cit y_ID.nextval,'" & txtCityName.Text & "','" & DListState.SelectedItem.Value & "' )"
cmd.CommandType = CommandType.Text
rd = cmd.ExecuteReader
MessageBox("New City has inserted")
End If
cmd.Cancel()
con.Close()
End Sub