I have a DataGridView with several columns that are all added at runtime. Some of the columns are also DataBound at runtime too. Now this has been working great but since I added a ComboBoxColumn, it won't save!
I get the error:This is the ComboBoxColumn. The code I am using to save is:Parameter @7 has no default value
Is it something to do with the code and column type that is stopping it from saving? I have tried both selecting values for each of the rows with the ComboBox and also have set .DefaultCellStyle.NullValue = "0" incase the user doesn't select a value.Code:If ExcelYear = "7" Then Dim MyExcelConnection As New System.Data.OleDb.OleDbConnection _ ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=S:\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$] ([StudentId],[StudentName],[ClassGrp],[TheDate],[Merits],[Demerits],[Penalty],[Lesson]," + _ "[TeachingGrp],[Staff],[Description],[Action],[MeritType]) VALUES(@1,@2,@3,@4,@5,@6,@7,@8,@9,@10,@11,@12,@13)" .CommandType = CommandType.Text .Connection = MyExcelConnection For Each Row As DataGridViewRow In DataGridView1.Rows For Col As Int32 = 1 To Row.Cells.Count .Parameters.Add(New OleDb.OleDbParameter("@" & Col, OleDb.OleDbType.Char)).Value = CStr(Row.Cells(Col - 1).Value) Next Col .ExecuteNonQuery() .Parameters.Clear() Next End With MyExcelConnection.Close() MyExcelConnection.Dispose() MyExcelConnection = Nothing
Any ideas?
Cheers![]()


Reply With Quote
Bookmarks