I am having 2 forms. The first form has countrycode and countryname and second form has statecode, statename, countryname(dropdown). I am able to fill the dropdown but m not able insert statename.. y so??
plss help
code to insert statename is as follows
Protected Sub btnInsert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnInsert.Click
Dim oconnection As New class1, newcode As String
oconnection.M_PreFix = "ST"
oconnection.M_CodeLen = 5
oconnection.M_PrimaryKey = "StateCode"
oconnection.M_Table = "State"
oconnection.M_Where = False
newcode = oconnection.GetNewCode()
txtStateCode.Text = newcode
btnInsert.Visible = True
Dim conn As New SqlConnection(ConfigurationManager.AppSettings("GalaCon"))
Dim cmd As New SqlCommand
conn.Open()
Dim dt As New DataTable
dt = oconnection.getdata(" select CountryCode from Country where CountryName = '" & cmbCountryName.SelectedValue & "' ")
cmd = New SqlCommand("Insert into State values('" & Trim(txtStateCode.Text) & "','" & dt.Rows(0).Item("CountryCode") & "','" & Trim(txtStateName.Text) & "') ", conn)
cmd.CommandTimeout = 0
cmd.ExecuteNonQuery()
lbmsg.Text = "Data entered successfully.. !!"
conn.Close()
txtStateCode.ReadOnly = True
Response.Write("<script type='text/javascript'>window.close();</script>")
End Sub
code to fill dropdown is as follows
Public Sub fill_country()
Dim oconnection As New class1
Dim query As String = "select * from Country order by CountryName"
Dim cmd As New SqlCommand(query)
cmbCountryName.DataSource = oconnection.getdata(cmd)
cmbCountryName.DataTextField = "CountryName"
cmbCountryName.DataValueField = "CountryCode"
cmbCountryName.DataBind()
cmbCountryName.Items.Insert(0, "Select Country")
End Sub