Hello,
Most of my experience in in VB6... I am trying to convert to VB.NET. I have visual studio 2013.
I have a datagridview with multiple comboboxes. The idea if for the user to select values for all combos and then click the "Save" button to update the database.
I am only storing the numeric equivalent which refers to the index. I cannot figure out how to retrieve the index of the selection in each cell. I was thinking somehow I could use ENUM but can't figure out how to use that either.
Attachment 146835
The database field "percent_type" holds a value of 0, 1 or 2 which corresponds to the choices in the drop down list.
I highlighted the code that refers to my problem area.
I have scoured the internet and tried many different things... this is my last resort... please help!!Code:Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click Dim db As New DataAccess.sqlDataBase("hp_accting") Dim dbReader As New DataAccess.sqlDataBase("hp_accting") Dim xColumn As Integer = 1 Try Do While xColumn < dtgAllocation.ColumnCount() For xAllocation As Integer = 0 To 13 Dim colcmb As DataGridViewColumn = DirectCast(dtgAllocation.Columns(xColumn), DataGridViewColumn) Dim cmb As DataGridViewComboBoxCell = DirectCast(dtgAllocation.Rows(xAllocation).Cells(xColumn), DataGridViewComboBoxCell) Dim readerCheck As SqlClient.SqlDataReader = dbReader.GetRecords("tax_owner_allocations", "*", "allocation_code = " & xAllocation.ToString & " AND ocode ='" & colcmb.Name.Trim.ToString & "' AND entity_num = '" & cmbEntity.Text.Substring(0, 8).Trim & "' AND projection_year = '" & cmbYear.Text & "'") If readerCheck.HasRows Then db.UpdateRecordField("UPDATE tax_owner_allocations SET percent_type = " & cmb.Value & " WHERE allocation_code = " & xAllocation.ToString & " AND ocode ='" & colcmb.Name.Trim.ToString & "' AND entity_num = '" & cmbEntity.Text.Substring(0, 8).Trim.ToString & "' AND projection_year = '" & cmbYear.Text.ToString & "'") Else db.InsertRecord("tax_owner_allocations", "ocode, entity_num, projection_year, allocation_code, percent_type", "'" & colcmb.Name.Trim & "', '" & cmbEntity.Text.Substring(0, 8).Trim.ToString & "', '" & cmbYear.Text & "'," & xAllocation.ToString & ", " & cmb.RowIndex.ToString) End If readerCheck.Close() colcmb.Dispose() cmb.Dispose() readerCheck = Nothing Next xColumn += 1 Loop db = Nothing MsgBox("Update was successful!", MessageBoxButtons.OK, "Update Complete") Catch ex As Exception MsgBox("An error occured while updating this record.", MsgBoxStyle.OkOnly, "Update Cancelled") End Try End Sub
Thank you in advance.
Chrissy





Reply With Quote
