Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21089

DataGrid update DB not working as it should

$
0
0
I have a DataGrid which is bound to an ADODC and it allows updates. The database consists of different tables and the SQL for this ADODC is "SELECT stID, stName, grID, grName FROM tblStudent, tblGroup WHERE tblGroup.grID=tblStudent.stGroup ORDER BY grName, stName". The student's group is referenced to the Group table Key field.
I want to be able to easily assign a student to a group by changing the Group column in the DataGrid. However, it changes the name of the group in tblGroup instead of the Group ID in tblStudent.
I can overcome this by showing stGroup in the datagrid and the user enters the Group code (key) instead of the group name but that is VERY messy!
In an ideal world I would have a combobox in the Group column and the user simply selects the correct group for that student.
Please can anyone help me with this, how to fix it, or suggest a different approach - preferably not msFlexGrid because that looks very complicated since it does not allow updates.
My code is below:
vb Code:
  1. Private Sub FillGrid()
  2. Dim sSQL As String
  3.    sSQL = "SELECT stID, stName, grID, grName FROM tblStudent, tblGroup WHERE tblGroup.grID=tblStudent.stGroup"
  4.    sSQL = sSQL & " ORDER BY grName, stName"
  5.    ADOAllocate.RecordSource = sSQL
  6.    ADOAllocate.CommandType = adCmdText
  7.    ADOAllocate.Refresh
  8.    dgAllocate.AllowRowSizing = False
  9.    dgAllocate.Columns(0).Width = 0            'hide Key row
  10.    dgAllocate.Columns(1).Width = 2500
  11.    dgAllocate.Columns(1).Locked = True        'can't change student name
  12.    dgAllocate.Columns(2).Width = 0            'hide group code
  13.    dgAllocate.Columns(3).Width = 900          'Group
  14.    dgAllocate.ScrollBars = dbgHorizontal
  15. End Sub

Viewing all articles
Browse latest Browse all 21089

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>