У меня проблема с этим Индексом вне диапазона, и я действительно не знаю, как решить эту проблему.Это код.
Sub insert()
Dim dt As DataTable
Try
For i As Integer = 0 To DataGridView1.Rows.Count - 1
exec("select * from TBL_SUMMARY1")
dt = exec("insert into TBL_SUMMARY1 values('" & DataGridView1.Rows(i).Cells(0).Value & "','" & DataGridView1.Rows(i).Cells(1).Value & "','" & DataGridView1.Rows(i).Cells(2).Value & "','" & DataGridView1.Rows(i).Cells(3).Value & "','" & DataGridView1.Rows(i).Cells(4).Value & "','" & DataGridView1.Rows(i).Cells(5).Value & "','" & DataGridView1.Rows(i).Cells(6).Value & "','" & DataGridView1.Rows(i).Cells(7).Value & "','" & DataGridView1.Rows(i).Cells(8).Value & "','" & DataGridView1.Rows(i).Cells(9).Value & "','" & DataGridView1.Rows(i).Cells(10).Value & "','" & DataGridView1.Rows(i).Cells(11).Value & "','" & DataGridView1.Rows(i).Cells(12).Value & "','" & DataGridView1.Rows(i).Cells(13).Value & "','" & DataGridView1.Rows(i).Cells(14).Value & "','" & DataGridView1.Rows(i).Cells(15).Value & "','" & DataGridView1.Rows(i).Cells(16).Value & "','" & DataGridView1.Rows(i).Cells(17).Value & "','" & DataGridView1.Rows(i).Cells(18).Value & "','" & DataGridView1.Rows(i).Cells(19).Value & "','" & DataGridView1.Rows(i).Cells(20).Value & "','" & DataGridView1.Rows(i).Cells(21).Value & "','" & DataGridView1.Rows(i).Cells(22).Value & "','" & Date.Today & "' )")
Next
MetroFramework.MetroMessageBox.Show(Me, "Insert Successfuly")
TextBox1.Text = ""
DataGridView1.Columns.Clear()
Catch ex As Exception
MsgBox(ex.Message)
End Try
также здесь при импорте некоторых файлов Excel и скрытии других данных.
Dim op As New OpenFileDialog
Dim partfile As String
Try
op.Filter = "XlS Files (*.xls)|*.xls|Excel Files (*.xlsx)|*.xlsx"
If op.ShowDialog = DialogResult.OK Then
TextBox1.Text = op.FileName
partfile = TextBox1.Text
con = New OleDbConnection("Provider = Microsoft.ACE.OLEDB.12.0;Data Source= '" & partfile & "';Extended Properties=""Excel 12.0 Xml;HDR = yes""")
da = New OleDbDataAdapter("Select * from [Summary$]", con)
da.TableMappings.Add("Table", "Myfile")
ds = New DataSet
da.Fill(ds)
ds.Tables(0).Rows.RemoveAt(0)
ds.Tables(0).Rows.RemoveAt(0)
ds.Tables(0).Rows.RemoveAt(0)
DataGridView1.DataSource = ds.Tables(0)
DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
DataGridView1.Refresh()
con.Close()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
После импорта появится сообщение Пример ошибки