473,320 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Form checkbox not saving values beyond first line

347 100+
I have a form in an application that I'm building and in it I have a datagridview that when a user clicks a checkbox on a line in the datagridview and "submits" the data, then the form will insert all of the data on that line (along with the code "Holiday") into a database. Currently if I click in the checkbox on any line other than the first line and put a line break on the "Try" statement, and then fire the submit_onclick event, I'm never reaching that break point but if I click on the checkbox on the first line and submit that data, that works and it behaves at I stated above. Here is the code as it stands currently:

Expand|Select|Wrap|Line Numbers
  1. Private Sub holidaysaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles holidaysaveButton.Click
  2.  
  3.         For Each dr As DataGridViewRow In DataGridView1.Rows
  4.             Dim cell1 As String
  5.             Dim cell2 As Date
  6.             Dim cell3 As String
  7.             Dim cell4 As String = "Holiday"
  8.  
  9.             For Each row As DataGridViewRow In DirectCast(Me.DataGridView1.Rows, IEnumerable)
  10.                 If Convert.ToBoolean(dr.Cells(4).Value) = "True" Then
  11.                     Dim str1 As String = row.Cells(1).Value.ToString
  12.                     Dim str2 As String = row.Cells(2).Value.ToString
  13.                     Dim str3 As String = row.Cells(3).Value.ToString
  14.                     Dim str4 As String = row.Cells(4).Value.ToString
  15.                 End If
  16.                 If row.Cells(4).Value IsNot Nothing Then
  17.                     cell1 = row.Cells(1).Value.ToString()
  18.                     cell2 = row.Cells(2).Value.ToString()
  19.                     cell3 = row.Cells(3).Value.ToString()
  20.                     Dim con As New SqlConnection
  21.                     Dim cmd As New SqlCommand
  22.                     Try
  23.                         con.ConnectionString = "Data Source=xxxxx;Initial Catalog=xxxxx;User ID=xxxxx;Password=xxxxx"
  24.                         con.Open()
  25.                         cmd.Connection = con
  26.                         cmd.CommandText = "INSERT INTO exceptions (employeenumber, exceptiondate, minutes, code) VALUES ('" & cell1 & "','" & cell2 & "','" & cell3 & "','" & cell4 & "')"
  27.                         cmd.ExecuteNonQuery()
  28.                         MessageBox.Show("Your data has been updated")
  29.                     Catch ex As Exception
  30.                         MessageBox.Show("Error while updating record on table..." & ex.Message, "Update Records")
  31.                     Finally
  32.                         con.Close()
  33.                     End Try
  34.                 End If
  35.                 DailySummaryReview.holidayaddButton.Enabled = False
  36.                 Me.Close()
  37.             Next
  38.         Next
  39.  
Can someone please tell me what I may be missing?

Thank you

Doug
May 23 '11 #1
1 1092
MrMancunian
569 Expert 512MB
Give line 16 a breakpoint and evaluate the value of row.Cells(4).Value. Also, note that your cellcount should be 0-based, so cells(4) implies that there are at least 5 cells.

Steven
May 26 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Kemal | last post by:
Hi, I have an xml file which I cant change, the problem is that the first line looks like this <?xml version="1.0" ?> with the rest of the xml being fine. However when I try to parse this I am...
2
by: RC | last post by:
Order for PHP get the array from a HTML form checkbox or select tag. The HTML name MUST with . For example: <form methos=POST action="myfile.php"> <select name="pets" multiple> <option...
16
by: shekharpati | last post by:
hi all, I,m trying to read a space delimited file with the use of formated input through fscanf. But surprisingly i am able to read all the 4999 lines of data except the "first line" which is...
4
by: News | last post by:
Hi Everyone, The attached code creates client connections to websphere queue managers and then processes an inquiry against them. The program functions when it gets options from the command...
2
by: alexsg | last post by:
I'm setting up a resolutions database where each resolution will be copied from Word documents and pasted into a memo field. The resolution will be in the form: Resolution title <cr> Project no...
3
by: jonathan184 | last post by:
Hi I am trying to get to values on each line of a text file and write to another file I am still new to this I tried to writing the following below Just to let you know i am still a newbie. ...
6
by: Karl | last post by:
Hi all, It may seem like a rather odd request (or not) but I would like to be able to create a file (doc, jpg, xls or one of many other files that can be automated) on a website and stream it to...
13
by: youngjin.michael | last post by:
Hello, I am new to Python and have one simple question to which I cannot find a satisfactory solution. I want to read text line-by-line from a text file, but want to ignore only the first line....
1
by: lorax | last post by:
I am new to this. I am recreating a form from ACCESS 2000 in Access 2010. The problem is that ACCESS no longer allow one to close a form without saving it. Form: a search form that allows people...
7
by: kino | last post by:
I am using this function to get data from a file void get() { string line; ifstream myfile; myfile.open ("jty.txt"); while (getline(myfile, line))
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.