Hi Laura
there is a small mistake in the code
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()*
**
*change this to *
**
* objDataSet.Tables(tblAttendance).AcceptChanges()*
* *
*Make the changes and let me know if you still find any errors*
**
On Wed, Jan 28, 2009 at 11:32 PM, The_Fruitman
<[email protected]>wrote:
>
> First thing that should be done is some cleanup work on the form. Do
> you really need to display all those checkboxes for every day? Think
> of the requirements of the program. If the user taking attendance
> must take attendance every day then shouldn't only 1 class sized (25
> in your case) set of checkboxes be available? Do you do anything
> behind the scenes that you need the additional checkboxes for?
>
> I would also recommend looking into a control called a checked list
> box. This would allow you to dynamically create the checkboxes on the
> form, as well as making the loop writing easier (you can easily get a
> count of the total number of items in the checked list box).
>
> Another thought that comes to mind for usability; is it easier for a
> user to mark who is present or who is absent? If the whole class is
> present would the user prefer not to click any check boxes or have to
> click them all?
>
>
> On Jan 28, 5:19 am, Laura <[email protected]> wrote:
> > I know the below code isnt right.
> > objCurrentRow1.Item("StudentID") = mintStudentID
> > objCurrentRow1.Item("Attendance Date") = dateToday
> > objCurrentRow1.Item("Present") = Tues1.CheckState
> > objDataSet.Tables("tblAttendance").Rows.Add(objCurrentRow1)
> >
> > Take the first line for example; what I need to get it to do is read
> > all the StudentIDs related to all the student names currently in the
> > listbox and write them to the database. I see what you're saying about
> > the loop, cos I need write into possibly 25 rows in the database.
> >
> > With the third line of that piece of code,
> >
> > objCurrentRow1.Item("Present") = Tues1.CheckState
> >
> > there are up to 25 checkboxes on the form for each day of the week
> > (chkTues1 chkTues2......chkTues25) so how can I get it to check the
> > state of all the checkboxes without writing 25lines of code?
> > I should probably also explain that on the form for recording the
> > attendance there is a list of checkboxes under each day of the week
> > and I have code behind the form so that if today is Wednesday - only
> > Wednesdays checkboxes are enabled.
> >
> > I realise that I'm going to have to put the 'save' code into a do
> > while loop of some sort but could you give me a bit more help??
> >
> > Thanks.
> >
> > On Jan 27, 7:58 pm, The_Fruitman <[email protected]> wrote:
> >
> >
> >
> > > 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 -- Hide quoted text -
> >
> > > - Show quoted text -- Hide quoted text -
> >
> > - Show quoted text -
--
Thanks & Regards
Harika
http://harikaworks.blogspot.com