I have a gradebook DB and when I calculate the averages, I dump them into a table in a different DB using the cSQL Statement below. I have two issues - one, I cannot update the new table because it has no primary key. Two, I am trying to add a AutoNumber Column to fix that, but nothing I do seems to add a new column for me. Here is the code - what am I missing?
cSQL = "Select [StudentID],[StudentLast] as [Last Name],[StudentFirst] as [First Name], [MI], "
cSQL = cSQL & "AVG(Grade) AS [Average], MAX([Letter]) as [Letter], COUNT([Grade]) as [# Assign] "
cSQL = cSQL & ",[Subject],[Term] INTO [SubjectAverages] in '" & AppDir & "averages.mdb'"
cSQL = cSQL & " FROM [Grades] WHERE [Subject] = '" & FixApost(cboSubject.Text) & "' AND [Term] = " & LastTerm
cSQL = cSQL & " GROUP BY [StudentLast],[StudentFirst],[MI],[StudentID],[Subject],[Term] ORDER BY [StudentLast],[StudentFirst],[MI] ;"
Try
'Use cSQL Statement to calculate Averages into table SubjectAverages in DB: 'Averages.mdb'
OpenDB2()
da = New OleDbDataAdapter(cSQL, con)
dt.Columns.Clear()
dt.Rows.Clear()
da.Fill(dt)
'Add New Column
dt.Columns.Add("Number", GetType(Integer))
'Are these needed?
dt.AcceptChanges()
da.Update(dt)
con.Close()
Catch ex As Exception
Me.Cursor = Cursors.Default
MessageBox.Show("Error during Chart Update." + ControlChars.CrLf + ex.Message, "Classroom Grader DB Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
CloseandDispose2()
Exit Sub
End Try
question from:
https://stackoverflow.com/questions/65929042/update-table-and-add-new-primary-index-column 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…