Click here to Skip to main content
15,890,512 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionChange the format Pin
Felix Holzinger7-Oct-17 11:51
Felix Holzinger7-Oct-17 11:51 
AnswerRe: Change the format Pin
Richard MacCutchan10-Oct-17 21:04
mveRichard MacCutchan10-Oct-17 21:04 
Questionsoftwares for agriculture irrigation with the help of visual basic Pin
Member 134513307-Oct-17 4:49
Member 134513307-Oct-17 4:49 
AnswerRe: softwares for agriculture irrigation with the help of visual basic Pin
OriginalGriff7-Oct-17 4:50
mveOriginalGriff7-Oct-17 4:50 
AnswerRe: softwares for agriculture irrigation with the help of visual basic Pin
Mycroft Holmes7-Oct-17 15:15
professionalMycroft Holmes7-Oct-17 15:15 
Questionsoftwares for agriculture irrigation with the help of visual basic Pin
Member 134513307-Oct-17 4:06
Member 134513307-Oct-17 4:06 
AnswerRe: softwares for agriculture irrigation with the help of visual basic Pin
OriginalGriff7-Oct-17 4:50
mveOriginalGriff7-Oct-17 4:50 
QuestionDataGridView with Two Datatables and Combobox Lookup Pin
billsut4-Oct-17 2:19
billsut4-Oct-17 2:19 
I have 2 tables in the same database.

tblAircraft - ACID, ACName

tblMaster - MasterID, ACID, and many others that are not relevant to my question.


tblAircraft is a lookup table with all the aircraft listed. tblMaster is the main table and holds all the detail information.

I have a DataGridView that has several columns. Column 1 is a combobox column that has the ACName from tblAircraft. The rest of the columns are textbox columns with data from tblMaster. My application works as far as displaying all the data and I can use a dataadapter update command to update tblMaster (good) and the other datasource updates tblAircraft (bad) with the DataGridView. My problem is that I want ACID in tblMaster to be updated with the ACID from the combobox. Of course it won't because it belongs to the datasource for tblAircraft. How can I use the selection in the combo box to update the tblMaster table along with the other fields in the DataGridView?

I have spent hours and hours trying to figure this out. I hope my explanation is clear. Thank you in advance for any help you can provide.

<pre>

Private Sub cboAC_SelectionChangeCommitted(sender As Object, e As EventArgs) Handles cboAC.SelectionChangeCommitted

dsACGrid = LoadDataSet()

'Refreshes DataGridView
If dgvTasks.ColumnCount > 0 Then
For i As Integer = 0 To dgvTasks.ColumnCount - 1
dgvTasks.Columns.RemoveAt(0)
Next
End If

'Connection obj to database
Conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\SupportGeneral.accdb"

Dim cbColumn As New DataGridViewComboBoxColumn With
{
.DataPropertyName = "ACName",
.DataSource = dsACGrid.Tables(1),
.DisplayMember = "ACName",
.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing,
.Name = "cbColumn",
.HeaderText = "Aircraft",
.SortMode = DataGridViewColumnSortMode.NotSortable,
.ValueMember = "ACName"
}

dgvTasks.Columns.Insert(0, cbColumn)

Dim GSTask As New DataGridViewTextBoxColumn With {.DataPropertyName = "GSTask", .HeaderText = "Gen Spt Task"}

Dim LCOMTask As New DataGridViewTextBoxColumn With {.DataPropertyName = "LCOMTask", .HeaderText = "LCOM Task"}

Dim AFSC As New DataGridViewTextBoxColumn With {.DataPropertyName = "AFSC", .HeaderText = "AFSC"}

Dim ReqSkill As New DataGridViewTextBoxColumn With {.DataPropertyName = "ReqSkill", .HeaderText = "Req Skill"}

Dim ReqGrade As New DataGridViewTextBoxColumn With {.DataPropertyName = "ReqGrade", .HeaderText = "Req Grade"}

Dim NotesQuestions As New DataGridViewTextBoxColumn With {.DataPropertyName = "NotesQuestions", .HeaderText = "Notes/Questions"}

Dim AvgTimeHours As New DataGridViewTextBoxColumn With {.DataPropertyName = "AvgTimeHours", .HeaderText = "Avg Time-Hours"}

Dim CrewSizeMin As New DataGridViewTextBoxColumn With {.DataPropertyName = "CrewSizeMin", .HeaderText = "Crew Size Min"}

Dim CrewSizeMax As New DataGridViewTextBoxColumn With {.DataPropertyName = "CrewSizeMax", .HeaderText = "Crew Size Max"}

Dim Manhours As New DataGridViewTextBoxColumn With {.DataPropertyName = "Manhours", .HeaderText = "Manhours"}

Dim FreqQty As New DataGridViewTextBoxColumn With {.DataPropertyName = "FreqQty", .HeaderText = "Freq Qty"}

Dim FreqRate As New DataGridViewTextBoxColumn With {.DataPropertyName = "FreqRate", .HeaderText = "Freq Rate"}

Dim PAFSC As New DataGridViewTextBoxColumn With {.DataPropertyName = "PAFSC", .HeaderText = "PAFSC"}

Dim PAFSCQty As New DataGridViewTextBoxColumn With {.DataPropertyName = "PAFSCQty", .HeaderText = "PAFSC Qty"}

Dim AltAFSC1 As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC1", .HeaderText = "Alt AFSC1"}

Dim AltAFSC1Qty As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC1Qty", .HeaderText = "Alt AFSC1 Qty"}

Dim AltAFSC2 As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC2", .HeaderText = "Alt AFSC2"}

Dim AltAFSC2Qty As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC2Qty", .HeaderText = "Alt AFSC2 Qty"}

Dim AltAFSC3 As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC3", .HeaderText = "Alt AFSC3"}

Dim AltAFSC3Qty As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC3Qty", .HeaderText = "Alt AFSC3 Qty"}

Dim AltAFSC4 As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC4", .HeaderText = "Alt AFSC4"}

Dim AltAFSC4Qty As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC4Qty", .HeaderText = "Alt AFSC4 Qty"}

Dim ACSelected As New DataGridViewCheckBoxColumn With {.DataPropertyName = "ACSelected", .HeaderText = "Selected"}

With dgvTasks
.AutoGenerateColumns = False
.Columns.AddRange(New DataGridViewColumn() {GSTask, LCOMTask, AFSC, ReqSkill, ReqGrade,
NotesQuestions, AvgTimeHours, CrewSizeMin, CrewSizeMax, Manhours, FreqQty, FreqRate,
PAFSC, PAFSCQty, AltAFSC1, AltAFSC1Qty, AltAFSC2, AltAFSC2Qty,
AltAFSC3, AltAFSC3Qty, AltAFSC4, AltAFSC4Qty, ACSelected})
End With

'Bind the dataset after all operation to the datagrid
dgvTasks.DataSource = dsACGrid.Tables(0)

End Sub


Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load

Conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\SupportGeneral.accdb"

'Loads dropdown for aircraft type
Dim strSQL As String = "Select * from tblAircraft"

Dim daAC As OleDbDataAdapter = New OleDbDataAdapter(strSQL, Conn)

daAC.Fill(dsAC, "tblAircaft")

Dim dr As DataRow = dsAC.Tables(0).NewRow()
dr("ACName") = ""
dsAC.Tables(0).Rows.InsertAt(dr, 0)

Using cmd As New OleDbCommand(strSQL, Conn)
With cboAC
.DataSource = dsAC.Tables(0)
.DisplayMember = "ACName"
.ValueMember = "ACName"
End With
End Using

dsAC.Tables.RemoveAt(0)

End Sub

Private Function LoadDataSet() As DataSet

Conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\SupportGeneral.accdb"

'This code refreshes the datasets and data tables.
If dtACGrid.Rows.Count > 0 Then
dsACGrid.Tables.RemoveAt(0)
dtACGrid.Clear()
End If

If dtAircraft.Rows.Count > 0 Then
dsACGrid.Tables.RemoveAt(0)
dtAircraft.Clear()
End If

dsACGrid.Tables.Add(dtACGrid)

'Load Master table
strACGrid = "select * from tblMaster where ACName = '" & cboAC.SelectedValue & "'"

daACGrid = New OleDbDataAdapter(strACGrid, Conn)
cbACGrid = New OleDbCommandBuilder(daACGrid)

cbACGrid.QuotePrefix = "["
cbACGrid.QuoteSuffix = "]"

daACGrid.Fill(dtACGrid)

dsACGrid.Tables.Add(dtAircraft)

'Load Aircraft table
strACGrid = "select * from tblAircraft"

daACGrid = New OleDbDataAdapter(strACGrid, Conn)
cbACGrid = New OleDbCommandBuilder(daACGrid)

cbACGrid.QuotePrefix = "["
cbACGrid.QuoteSuffix = "]"

daACGrid.Fill(dtAircraft)

Return dsACGrid

End Function

Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click

daACGrid.Update(dtACGrid)
Me.Close()

End Sub


End Class

</pre>
AnswerRe: DataGridView with Two Datatables and Combobox Lookup Pin
Mycroft Holmes4-Oct-17 13:30
professionalMycroft Holmes4-Oct-17 13:30 
QuestionResizing images Pin
A_Griffin3-Oct-17 2:03
A_Griffin3-Oct-17 2:03 
AnswerRe: Resizing images Pin
Richard MacCutchan3-Oct-17 6:31
mveRichard MacCutchan3-Oct-17 6:31 
GeneralRe: Resizing images Pin
A_Griffin3-Oct-17 8:14
A_Griffin3-Oct-17 8:14 
Questiondatabase design for financial accounting Pin
Mohammad Kamil1-Oct-17 8:47
Mohammad Kamil1-Oct-17 8:47 
AnswerRe: database design for financial accounting Pin
Mycroft Holmes1-Oct-17 13:28
professionalMycroft Holmes1-Oct-17 13:28 
QuestionRetrieve data from Acess database after login form Pin
Charles9730-Sep-17 4:48
Charles9730-Sep-17 4:48 
AnswerRe: Retrieve data from Acess database after login form Pin
Richard Andrew x6430-Sep-17 5:15
professionalRichard Andrew x6430-Sep-17 5:15 
QuestionI am changing code from vb6 windows application to vb.net windows application..getting error on EOF. sAn unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in Test.exe Additional information: Operation is not allowed Pin
Member 1075459525-Sep-17 6:27
Member 1075459525-Sep-17 6:27 
SuggestionRe: I am changing code from vb6 windows application to vb.net windows application..getting error on EOF. sAn unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in Test.exe Additional information: Operation is not allo Pin
Richard Deeming25-Sep-17 6:39
mveRichard Deeming25-Sep-17 6:39 
GeneralRe: I am changing code from vb6 windows application to vb.net windows application..getting error on EOF. sAn unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in Test.exe Additional information: Operation is not allo Pin
Member 1075459525-Sep-17 7:07
Member 1075459525-Sep-17 7:07 
AnswerRe: I am changing code from vb6 windows application to vb.net windows application..getting error on EOF. sAn unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in Test.exe Additional information: Operation is not allo Pin
Wendelius25-Sep-17 10:16
mentorWendelius25-Sep-17 10:16 
QuestionUse a variable or text box in Sql WHERE clause Pin
Member 1300905323-Sep-17 9:31
Member 1300905323-Sep-17 9:31 
AnswerRe: Use a variable or text box in Sql WHERE clause Pin
Afzaal Ahmad Zeeshan23-Sep-17 10:28
professionalAfzaal Ahmad Zeeshan23-Sep-17 10:28 
QuestionVLC Player User-Agent for vb6 Pin
Member 1341240517-Sep-17 17:01
Member 1341240517-Sep-17 17:01 
QuestionVB Form Search XLSX Pin
Member 24539047-Sep-17 10:41
Member 24539047-Sep-17 10:41 
AnswerRe: VB Form Search XLSX Pin
Richard MacCutchan7-Sep-17 19:21
mveRichard MacCutchan7-Sep-17 19:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.