سلام
از شیوه فوق نتوانستم استفاده کنم . من تکه کدی که اسلاعات را از اکسل خوانده و در اکسس ذخیره میکنه را مینویسم .
یکسری شماره را در comment ها قرار دادم برای توضیحات
Try
Dim sqlSend As String
'< 1 >---
Me.CreateWorkSheet(Trim(FileCode))
ExcelProvider = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Trim(SavePath) & "Res_" & Trim(FileCode) & ".xls" & ";" + "Extended Properties=Excel 8.0;"
con_excel = New OleDbConnection(ExcelProvider)
con_excel.Open()
'< 2 >---
For iCount As Byte = LBound(AllVragen) To UBound(AllVragen)
'< 3 >---
sqlSend = "SELECT " & AllVragen(iCount) & " AS " & AllVragen(iCount) & ","
sqlSend = sqlSend & " COUNT(" & AllVragen(iCount) & ") AS Resultaat, " ' Vraag count
sqlSend = sqlSend & " ROUND(Resultaat * 100 / " & recCount - MissRecord(iCount) & ",1) AS Percentage," ' Percentage 1
sqlSend = sqlSend & " ROUND(Resultaat * 100 /" & recCount - MissRecord(iCount) & ",5) AS NPercentage" ' Precentage 5
'sqlSend = sqlSend & " Percentage AS Cumulatieve" ' Cumulatieve 1
sqlSend = sqlSend & " FROM " & Trim(FileCode)
sqlSend = sqlSend & " WHERE " & AllVragen(iCount) & " IS NOT NULL "
sqlSend = sqlSend & " GROUP BY " & AllVragen(iCount)
Me.DataGridViewFillingU(dgvUser, sqlSend, Trim(FileCode))
'< 4 >---
NewSql = "INSERT INTO " & Trim(FileCode) & "(Vraag, Resultaat, FPrecentage, SPrecentage, Cumulatieve) VALUES ( ' ', ' ', ' ', ' ', ' ')"
Me.InsertINTOWorkSheet(NewSql)
If dgvUser.Rows.Count > 0 Then
For id As Integer = 0 To dgvUser.Rows.Count - 1
NewSql = "('" & dgvUser.Rows(id).Cells(0).Text & "','" ' vraag
NewSql = NewSql & dgvUser.Rows(id).Cells(1).Text & "','" ' Resultaat
NewSql = NewSql & dgvUser.Rows(id).Cells(2).Text & "','" ' Percentage 1
NewSql = NewSql & dgvUser.Rows(id).Cells(3).Text & "','" ' Percentage 5
Cum = Cum + dgvUser.Rows(id).Cells(3).Text
NewSql = NewSql & Math.Round(Cum, 1) & "')" ' Cumulatieve
Co1 = Co1 + dgvUser.Rows(id).Cells(1).Text
Co2 = Co2 + dgvUser.Rows(id).Cells(2).Text
Co3 = Co3 + dgvUser.Rows(id).Cells(3).Text
NewSql = "INSERT INTO " & Trim(FileCode) & " (Vraag, Resultaat, FPrecentage, SPrecentage, Cumulatieve) VALUES " & NewSql
'< 5 >---
Me.InsertINTOWorkSheet(NewSql)
Next
'< 6 >---
NewSql = "INSERT INTO " & Trim(FileCode) & " (Vraag, Resultaat, FPrecentage, SPrecentage, Cumulatieve) VALUES ( 'tataal', '" & Co1 & "', ' " & Co2 & "', ' " & Co3 & "', ' ')"
Me.InsertINTOWorkSheet(NewSql)
'< 7 >---
NewSql = "INSERT INTO " & Trim(FileCode) & " (Vraag, Resultaat, FPrecentage, SPrecentage, Cumulatieve) VALUES ( 'missing', '" & recCount - Co1 & "', ' ',' ' , ' ')"
Me.InsertINTOWorkSheet(NewSql)
Co1 = 0 : Co2 = 0 : Co3 = 0 : Cum = 0
End If
Next
con_excel.Close()
Catch ex As Exception
Me.AlertMsg(ex.Message)
End Try
کامنت 1 : یک worksheet در اکسس ایجاد میکند
کامنت 2 : قبلا نام فیلدهای اکسس را در آرایه ذخیره کرده ام و در این قسمت همه جداول خوانده میشوند
کامنت 3 : اطلاعات از بانک اکسس خوانده شده و یکسری محاسبات روی آن انجام میشود و در datagridview نمایش داده میشود.
کامنت 4 : توسط دستور insert into و تابع Me.InsertINTOWorkSheet(NewSql) یک خط خالی در اکسس ایجاد میشود و اطلاعات از datagridview دوباره خوانده شده و در سطر بعد اکسس با دستور Me.InsertINTOWorkSheet(NewSql) ذخیره میشود.
کامنت 6 : مقادیر مجموع بدست آمده در بانک اکسس ذخیره میشود.
کامنت 7 : یک خط خالی در اکسس ذخیره میشود.
حال به نظر شما چکار میتوان کرد که اینهمه مراجعه به بانک اکسل نداشته باشیم ؟