This question is about a project HannesTheGreat and JavaJawa have helped me with but anyone feel free to help!
The problem is that I am saving from a DataGridView to a Spreadsheet (which works great!!). I have changed one of the columns so that it is a DataGridViewComboboxColumn so that user can select from a number of values - both numerical and Text. The Column is called Lesson and basically holds details about the Lesson that an incident with a student happened. Here's the weird part - It seems that if the Spreadsheet has a lot of rows, the program returns a Data Type Mismatch in Criteria Expression on that column but if the Spreadsheet only has say 150 rows, it saves! The Data Type Mismatch stops on this line:
Code:
.ExecuteNonQuery()
All 7 spreadsheets (1 for each school Year from 7 - 13) that the data is saved to are identical, they have same columns and are all named identically. Infact they were all created by copying and pasting the original.
Code I am using to save is - this is just for 1 of the yeargroups (7):
Code:
If ExcelYear = "7" Then
Dim MyExcelConnection As New System.Data.OleDb.OleDbConnection _
("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\logon\shared\Penalty Points\08-09\Year 7 2008-09.xls;Extended Properties=""Excel 8.0;HDR=Yes;IMEX=0""")
MyExcelConnection.Open()
With myInsertCommand
.CommandText = "Insert INTO [Sheet1$] ([ID],[Name],[Form],[Date],[Merits],[Demerits],[Lesson]," + _
"[Group],[Staff],[Description],[Action],[MeritType]) VALUES(@1,@2,@3,@4,@5,@6,@7,@8,@9,@10,@11,@12)"
.CommandType = CommandType.Text
.Connection = MyExcelConnection
For Each Row As DataGridViewRow In DataGridView1.Rows
For Col As Int32 = 1 To Row.Cells.Count
If Not CStr(Row.Cells(Col - 1).Value) = String.Empty Then
.Parameters.Add(New OleDb.OleDbParameter("@" & Col, OleDb.OleDbType.Char)).Value = CStr(Row.Cells(Col - 1).Value)
Else
.Parameters.Add(New OleDb.OleDbParameter("@" & Col, OleDb.OleDbType.Char)).Value = CStr(Row.Cells(Col - 1).Value)
'.Parameters.Item("@7").Value = "0"
End If
Next Col
.ExecuteNonQuery()
.Parameters.Clear()
Next
End With
MyExcelConnection.Close()
MyExcelConnection.Dispose()
MyExcelConnection = Nothing
and the code for the DataGridViewComboBoxColumn is:
Code:
Dim Lesson As New DataGridViewComboBoxColumn
DataGridView1.Columns.Add("Lesson", "Lesson")
With Lesson
.Name = "Lesson"
.HeaderText = "Lesson"
.Width = 275
.Visible = True
.ReadOnly = False
'.AutoComplete = True
.Items.Add("AM Reg.")
.Items.Add("1")
.Items.Add("2")
.Items.Add("Break")
.Items.Add("3")
.Items.Add("4")
.Items.Add("Lunch")
.Items.Add("5")
.Items.Add("Other")
.Items.Add("!")
End With
DataGridView1.Columns.Add(Lesson)
Is can't be the code as it works for Years 12 & 13 - they only have around 160 rows each. Years 7 - 11 have between 5000 - 6000 rows and it won't save to them.
Any ideas please?
Last edited by brjames32; December 4th, 2008 at 02:47 AM.
The choices in ComboBoxColumn (Lesson) are : Am Reg., 1, 2, Break, 3, 4, Lunch, 5, Other
They are a mixture of Chars and Numbers. The Spreadsheets are Office 2003 and none of them are over 3MB in size so that 16k shouldn't be affecting this. The first 5 Spreadsheets (the ones that it won't save the Lesson column) are around 7000 rows in size.
The reason I am saving to a spreadsheet is that if you notice, several of the spreadsheet fields contain complicated formulas used to work out Penalty/Demerits Point etc. As far as I know, you cannot do this with a Database otherwise I would have been using one as they are much easier.
Can this be done in Access?
As to why it is executing over and over, when the user enters data, there may be up to 35 rows to be entered into the spreadsheet at a time. That's why is executing over and over until the last row.
If you want more background info on my project, look at this thread. Infact I think you contributed too!
Thanks so far . . . . .
Last edited by brjames32; December 5th, 2008 at 06:35 AM.
Thanks again for your suggestions! Although I really don't have much time left to work on this, I will give it a try.
How would I go about doing the sort of Calculations that I use in my Spreadsheet in VB before saving to DB?? I can do the saving part easily enough. Trouble is there may be 30-35 rows of info needing calculations and then saving at a time!
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.