I have managed to insert only 1 value, the first value I insert in the database.
The problem is, that I have more than 1 value in the combobox, but it only inserts the first one.
This is the code I have:
Dim query1 As New OleDbCommand(" SELECT MembrosCompasso.BI, MembrosCompasso.Ano FROM Compasso INNER JOIN MembrosCompasso ON Compasso.idCompasso = MembrosCompasso.idCompasso WHERE BI=@BI ", con)
query1.Parameters.Add("@BI", OleDbType.VarChar).Value = BI.Text
Dim dr1 As OleDbDataReader = query1.ExecuteReader
Try
If dr1.HasRows Then
dr1.Read()
Ano.Items.Item.add(dr1("Ano"))
Else
MsgBox("Não exsitem registos!")
End If
Catch ex As Exception
' tratamento de erros
Finally
dr.Close()
con.Close()
End Try
When you’re using a DataReader, the current position advances by one row every time you call the
.Readmethod, you don’t get all the records in the reader with one call.Readreturns a boolean that tells you whether it succeeded or not so that you know whether you can advance to the next record, so your code should look more like: