inserting items to dropdownlist!!!!!

windows

Guest
Hello everybody,
The cod below do have a dropdownlist that populates what's in my sql database, and when i insert a new type and click on add, it actually inserts it to the dropdownlist but not to my database...


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim strConn As String = "server=***;uid=***;pwd=***;database=***"
Dim sql As String = "Select type from Types"
Dim conn As New SqlConnection(strConn)
Dim objDR As SqlDataReader
Dim Cmd As New SqlCommand(sql, conn)

conn.Open()
objDR = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
ddl.DataSource = objDR
ddl.DataTextField = "type"
ddl.DataBind()
Dim myDefaultItem As ListItem = New ListItem("[Types]", String.Empty)
myDefaultItem.Selected = True
ddl.Items.Insert(0, myDefaultItem)
End If

End Sub

Sub doit(ByVal Source As Object, ByVal E As EventArgs)
If text1.text <> "" Then ddl.Items.Insert(0, New ListItem(text1.text))
ddl.SelectedIndex = 0
End Sub




The thing that's not working is how to connect or save what i just added to my dropdownlist into my sql database (Binding the new entered items to my database).Noting that my database table has only type and id in it.
I really appreciate any help...You need to do an insert statement to your database table.

EricThanks alot Eric..
I managed that...
 
Back
Top