How to adding data from a checked list box into database

Mar 11 2008 4:30 PM
Hi again i have one single question to make. I have this code, which is for adding data from a checked list box into a db using the For loop: Dim i As Integer
For i = 0 To (chlbProducts.Items.Count - 1)
If (chlbProducts.GetItemChecked(i)) = True Then
MessageBox.Show("GG man!!!")
Else
MessageBox.Show("ouuuups!!!")
End If
Next i
 
and i have also this code, which is the add of a customer into a db:
 
Dim con As OleDbConnection
Dim da As New OleDbDataAdapter
Dim fname As String = txtFName.Text
Dim lname As String = txtLName.Text
Dim city As String = cmbCity.Text
Dim State As String = cmbLocation.Text
Dim male As String = "Male"
Dim female As String = "Female"
con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\My Documents\Test.mdb")
con.Open()
Dim Trans As OleDbTransaction = con.BeginTransaction
Dim command As New OleDbCommand
command.Connection = con
command.Transaction = Trans
If rbtMale.Checked = True Then
command.CommandText = "INSERT INTO PersonalInfo(FirstName, LastName, Sex, State, City) values ('" & fname & "','" & lname & "','" & male & "','" & State & "','" & city & "')"
Else
command.CommandText = "INSERT INTO PersonalInfo(FirstName, LastName, Sex, State, City) values ('" & fname & "','" & lname & "','" & female & "','" & State & "','" & city & "')"
End If
'command.CommandText = "INSERT INTO PersonalInfo(FirstName, LastName) values ('" & fname & "','" & lname & "')"
Try
da.InsertCommand = command
da.InsertCommand.ExecuteNonQuery()
StatusText.Text = "adding Personal Info..."
Trans.Commit()
fname = ""
lname = ""
StatusText.Text = "Done"
MessageBox.Show("Saved succesfully", "Adding Personal Info Data", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
Trans.Rollback()
StatusText.Text = "Error in the proccess of adding Info"
MessageBox.Show("Error adding data", "Adding Personal Info Data", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End Try
con.Close()
command.Dispose()
da.Dispose()
Trans.Dispose()
My problem is that i already have one if statement in the radio buttons section, and i dont know how can i add a second IF statement into the INSERT  statement
So:
What I need is to help me by telling me how can i add the For loop statement into the INSERT  statement.
 
Thanks again in advance,
Alex

Answers (1)