Click here to Skip to main content
15,883,773 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
hi
please help me in my project i want to insert the value selected from drop down list into an column in my database using the asp.net in visual studio
[EDIT - OP code from comments]

i use this code to define the droplist
VB
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 If Not IsPostBack Then

 Dim cn As OleDbConnection = New OleDbConnection()

 cn.ConnectionString = ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\user\Desktop\web programming\\IULWebInformationSystem1\IULWebInformationSystem1\\App_Data\IUlDB.accdb;Persist Security Info=True")



 Dim ad As OleDbDataAdapter = New OleDbDataAdapter("Select Nationality From Nationality where Nationality=", cn)

 Dim dt As DataTable = New DataTable()
 ad.Fill(dt)


 NationalityDropList.DataValueField = "Nat_ID"
 NationalityDropList.DataTextField = "Nat_ID"
 NationalityDropList.DataBind()

and this to insert the data
VB
Protected Sub NextBtn_Click(ByVal sender As Object, ByVal e As EventArgs) Handles NextBtn.Click

 con = New OleDbConnection
 con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\user\Desktop\web programming\\IULWebInformationSystem1\IULWebInformationSystem1\App_Data\IUlDB.accdb;Persist Security Info=True"
 con.Open()
 sqlquery = "insert into Teacher values ('" & txtid.Text & "','" & FirstNameTxtBox.Text & "','" & MiddelNameTxtBox.Text & "','" & LastNameTxtBox.Text & "','" & txtBD.Text & "','" & POBTxtBox.Text & "','" & NationalityDropList.SelectedValue & "','" & Gendrplist.SelectedValue & "')"
 cmd = New OleDbCommand(sqlquery, con)
 cmd.ExecuteNonQuery()
 con.Open()
 txtid.Text = ""
 FirstNameTxtBox.Text = ""
 MiddelNameTxtBox.Text = ""
 LastNameTxtBox.Text = ""
 txtBD.Text = ""
 POBTxtBox.Text = ""
 NationalityDropList.SelectedValue = ""
 Gendrplist.SelectedValue = ""
Posted
Updated 28-May-14 7:15am
v2
Comments
Member 10850225 28-May-14 12:53pm    
otected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then

Dim cn As OleDbConnection = New OleDbConnection()

cn.ConnectionString = ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\user\Desktop\web programming\\IULWebInformationSystem1\IULWebInformationSystem1\\App_Data\IUlDB.accdb;Persist Security Info=True")



Dim ad As OleDbDataAdapter = New OleDbDataAdapter("Select Nationality From Nationality where Nationality=", cn)

Dim dt As DataTable = New DataTable()
ad.Fill(dt)


NationalityDropList.DataValueField = "Nat_ID"
NationalityDropList.DataTextField = "Nat_ID"
NationalityDropList.DataBind()
Member 10850225 28-May-14 12:54pm    
i use this code to define the droplist
Member 10850225 28-May-14 12:59pm    
Protected Sub NextBtn_Click(ByVal sender As Object, ByVal e As EventArgs) Handles NextBtn.Click

con = New OleDbConnection
con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\user\Desktop\web programming\\IULWebInformationSystem1\IULWebInformationSystem1\App_Data\IUlDB.accdb;Persist Security Info=True"
con.Open()
sqlquery = "insert into Teacher values ('" & txtid.Text & "','" & FirstNameTxtBox.Text & "','" & MiddelNameTxtBox.Text & "','" & LastNameTxtBox.Text & "','" & txtBD.Text & "','" & POBTxtBox.Text & "','" & NationalityDropList.SelectedValue & "','" & Gendrplist.SelectedValue & "')"
cmd = New OleDbCommand(sqlquery, con)
cmd.ExecuteNonQuery()
con.Open()
txtid.Text = ""
FirstNameTxtBox.Text = ""
MiddelNameTxtBox.Text = ""
LastNameTxtBox.Text = ""
txtBD.Text = ""
POBTxtBox.Text = ""
NationalityDropList.SelectedValue = ""
Gendrplist.SelectedValue = ""



and this to insert the data
[no name] 28-May-14 13:09pm    
Okay... and the problem is? Other than posting your code as a comment that is.
Member 10850225 29-May-14 3:49am    
I need to know how to insert the values selected from drop list into the access database

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900