Add to a database through a combobox

bbelect

Member
Joined
Apr 20, 2007
Messages
14
Programming Experience
1-3
Hi all.
Just a quick one how would i add a value typed in a combobox to a database. My database is only one table of names.

So basically how to add the valuetyped in combox1.text
Thanks
 
Last edited:
I have been trying this code in a button click event but it does not add to the database.

VB.NET:
Me.hNameComboBox.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.NameDataSet1, "tblName.lName"))
            Me.BindingContext(Me.NameDataSet1, "tblName").EndCurrentEdit()
            Me.NameDataAdapter1.Update(Me.NameDataSet1, "tblName")
            Me.NameDataSet1.AcceptChanges()
 
I have also tried this but nothing works
VB.NET:
 Dim oDR As DataRow
            oDR = NameDataSet1.Tables("tblName").NewRow()
            oDR.BeginEdit()

            oDR("IName") = hNameComboBox.Text

            oDR.EndEdit()

            NameDataSet1.Tables("tblName").Rows.Add(oDR)
 
I feel with this im on the right track but it does not work. By the way my table only has one colum name. When i do this it inserts a blank value in my table.

VB.NET:
Dim datarowCurrent As NameDataSet.tblNameRow
            datarowCurrent = NameDataSet1.tblName.NewtblNameRow
            datarowCurrent.lName = hNameComboBox.Text

            NameDataSet1.tblName.AddtblNameRow(datarowCurrent)
            Call saveChangesToDatabase()

Private Sub saveChangesToDatabase()
        Dim dsUpdates As DataSet

        dsUpdates = NameDataSet1.GetChanges
        If Not (dsUpdates Is Nothing) Then
            NameDataAdapter1.Update(NameDataSet1)
            NameDataSet1.AcceptChanges()
        End If
    End Sub

NB IName is the column name in the tblName table
 
Back
Top