You have several possible issues that are causing the error.
Think about the logic behind these two statements.
mintStudentID = objDataSet.Tables("tblStudent").Rows.Count
objCurrentRow1.Item("StudentID") = mintStudentID
I don't think you really want to be doing this.
Think about what happens when the following statements are executed:
objCurrentRow1.Item("StudentID") = mintStudentID
objCurrentRow1.Item("Attendance Date") = dateToday
objCurrentRow1.Item("Present") = Tues1.CheckState
objDataSet.Tables("tblAttendance").Rows.Add(objCurrentRow1)
It seems to me that you are adding the same information every time.
This (just speculating on your database design) would cause primary
key violations.
Also, a more detailed error message would be helpful.
I would recommend using some error handling as well (Try Catch
blocks).
For the listbox information you will need to determine which student's
names are checked and which names are not checked. For you this may
be easiest to do with a loop. You state you also need to get the
student id for each student name so that you can do your update.
There are various ways to do this, but based on the programming skills
I've seen from your other posts it may be easier for you to do this
through a loop as well, even though this requires additional
processing time.
On Jan 27, 8:55 am, Laura <[email protected]> wrote:
> Thanks for the help and I appreciate your advice.
> I have abandoned doing what I was intending to do and have since found
> a way around the problem. I think the main reason I wanted to do it
> that way initially was for visual appeal. However I have moved on with
> my project (the project I'm working on is an attendance recording and
> monitoring system for a small secondary school, its my final year
> project undertaking for college).
>
> I keep getting the following error as I am trying to get the 'save'
> part of the system going and was hoping for some help:
>
> OleDbException was unhandled
> Syntax error in INSERT INTO statement
>
> and the line of code the error points to goes as follows:
>
> objAttendanceDA.Update(objDataSet, "tblAttendance")
>
> The rest of my code is :
>
> Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e
> As System.EventArgs) Handles btnSave.Click
> 'Save the attendance
> Dim dateToday As Date = Now.Date
>
> 'setup the relationship
> objDataSet.Relations.Clear()
> objDataSet.Relations.Add("Class2Student", _
> objDataSet.Tables("tblClass").Columns
> ("ClassID"), _
> objDataSet.Tables
> ("tblStudent").Columns("ClassID"))
> objDataSet.Relations.Add("Student2Attendance", _
> objDataSet.Tables
> ("tblStudent").Columns("StudentID"), _
> objDataSet.Tables
> ("tblAttendance").Columns("StudentID"))
>
> 'Select the next row
> objCurrentRow1 = objDataSet.Tables("tblAttendance").NewRow
> mintStudentID = objDataSet.Tables("tblStudent").Rows.Count
>
> objCurrentRow1.Item("StudentID") = mintStudentID
> objCurrentRow1.Item("Attendance Date") = dateToday
> objCurrentRow1.Item("Present") = Tues1.CheckState
> objDataSet.Tables("tblAttendance").Rows.Add(objCurrentRow1)
> objAttendanceDA.Update(objDataSet, "tblAttendance")
> objDataSet.AcceptChanges()
>
> MsgBox("Saving Complete", MsgBoxStyle.OkOnly, "Saved")
>
> End Sub
>
> I think I might have an idea as to why I keep getting the error. On my
> windows form you select a class from a combobox and then the class
> list (all the student names) are populated into a listbox. We'll say
> there are 25 names, then there is also 25 checkboxes next to the list
> of names. If all students are present, all checkboxes are checked. So
> what the save button really needs to do is save the attendance for the
> class, but the code I have so far is only kinda for one row. Also to
> save to the Attendance table, a StudentID is needed and I don't really
> know how to deal with that in my code. All the names that come into
> the list box have an associated StudentID and it is those ID I need to
> save.
>
> I hope the way I have explained this is somewhat clear and any help
> would be greatly appreciated.
>
> Thanks.
> On Jan 24, 10:13 am, Kabeer <[email protected]> wrote:
>
>
>
> > Hi,
>
> > why you want to like this ?
> > according to me its not a good programming.
> > as per The_Fruitman you need gridview on your web page.
>
> > its not well but do this.
> > get records in say Datatable
> > Read the Table Entry one by one after fill it with your records.
> > use loop for fill the textboxes
> > like
> > For init to dt.rows.count -1
> > REM here fill your text boxes one by one with respect to record and
> > dt.rows[i]
> > end for
>
> > For this you have to define your textboxes id at runtime
> > like <asp:TextBox id="txtvalue" & i ..... />
> > here i means the value as per your recoed.- Hide quoted text -
>
> - Show quoted text -