Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi.
I am totally new to visual studio.

My Code show below.

ports System.IO
Imports System.Data
Imports System.Data.OleDb

Public Class ImportData1

    Private Sub ImportData1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        TxtFilePath.Text = "Place your file in D:\FileToImport Folder. File name should be MatRegFile.csv"

    End Sub

    Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click

        Me.Close()

    End Sub

    Private Sub btnImport_Click(sender As Object, e As EventArgs) Handles btnImport.Click

        Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Mihir\Documents\MiniAGAppDB.accdb;Persist Security Info=True")
        Dim cmd As OleDbCommand
        Dim querryStr As String

        Try

            querryStr = "Select * InTo Temp1 From [Text;FMT=Delimited;Database=D:\FileToImport;HDR=Yes].[MatRegFile.csv]"
            MessageBox.Show(querryStr)
            cmd = New OleDbCommand(querryStr, conn)
            conn.Open()
            cmd.ExecuteNonQuery()
            conn.Close()

            querryStr = "Insert InTo MaterialRegister ([Company_Code],[Company_Name],[Material_Code],[Material_Name],[Credit_Qty],[Debit_Qty],[Material_Count],[Material_Flag],[Material_Date],[Material_Inv_No],[Material_Party_Code],[Material_Party_Name],[Remark],[Entry_Flag],[Creation_Date],[User_Name]) Select [Company_Code],[Company_Name],[Material_Code],[Material_Name],[Credit_Qty],[Debit_Qty],[Material_Count],[Material_Flag],[Material_Date],[Material_Inv_No],[Material_Party_Code],[Material_Party_Name],[Remark],[Entry_Flag],[Creation_Date],[User_Name] From Temp1"
            cmd = New OleDbCommand(querryStr, conn)
            conn.Open()
            cmd.ExecuteNonQuery()
            conn.Close()

            querryStr = "Drop Table Temp1"
            cmd = New OleDbCommand(querryStr, conn)
            conn.Open()
            cmd.ExecuteNonQuery()
            conn.Close()

        Catch ex As Exception

            MessageBox.Show(ex.Message)

        End Try

    End Sub

End Class


When I run the windows form application I get following error message at line
cmd.ExecuteNonQuery() code below "Insert Into MaterialRegister"


"
Visual studio 2017 System.AccessViolationException 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'
"

I am using windows 7 ultimate 64 bit edition with SP1, Visual Studio 2017 and .Net framework 4.6 with MS access database and Crystal report.

Please help......

What I have tried:

I don't know what to try as I am totally new to visual studio.
Posted
Updated 3-Sep-19 22:42pm

1 solution

It is most likely that the previous SELECT INTO command did not create the data that you expect. You need to check the return value from each call to ExecuteNonQuery to see that it succeeded.
 
Share this answer
 
Comments
MKP75 4-Sep-19 4:54am    
Thanks for the reply. The Select into Temp1 statement creates the Temp1 Table in access database and the data is also inserted into Temp1 table from CSV file.

Then it comes to Insert into MaterialRegister statement after that the error is thrown on ExecuteNonQuery Statement.

Actually the code worked for first 2 times then it started giving the error.
Richard MacCutchan 4-Sep-19 5:05am    
OK, but the only way to find out why the error occurs is to use the debugger to check the data that you are processing. And, as I said earlier, check the return values from your system/library calls. Do not assume that just because they do not throw an exception that they have done what you think.
MKP75 4-Sep-19 5:16am    
Dim querryStr1 As String
MKP75 4-Sep-19 5:15am    
Thanks I will do that and get back. Thanks
MKP75 6-Sep-19 3:10am    
This is what I get when I debug the program

'MiniAGApp.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MiniAGApp.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\Mihir\Documents\Visual Studio 2017\Projects\MiniAGApp\MiniAGApp\bin\Debug\MiniAGApp.exe'. Symbols loaded.
'MiniAGApp.exe' (CLR v4.0.30319: MiniAGApp.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.VisualBasic\v4.0_10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualBasic.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MiniAGApp.exe' (CLR v4.0.30319: MiniAGApp.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MiniAGApp.exe' (CLR v4.0.30319: MiniAGApp.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MiniAGApp.exe' (CLR v4.0.30319: MiniAGApp.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MiniAGApp.exe' (CLR v4.0.30319: MiniAGApp.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MiniAGApp.exe' (CLR v4.0.30319: MiniAGApp.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Remoting\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Remoting.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MiniAGApp.exe' (CLR v4.0.30319: MiniAGApp.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MiniAGApp.exe' (CLR v4.0.30319: MiniAGApp.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MiniAGApp.exe' (CLR v4.0.30319: MiniAGApp.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MiniAGApp.exe' (CLR v4.0.30319: MiniAGApp.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Numerics\v4.0_4.0.0.0__b77a5c561934e089\System.Numerics.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MiniAGApp.exe' (CLR v4.0.30319: MiniAGApp.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MiniAGApp.exe' (CLR v4.0.30319: MiniAGApp.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.Transactions\v4.0_4.0.0.0__b77a5c561934e089\System.Transactions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MiniAGApp.exe' (CLR v4.0.30319: MiniAGApp.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MiniAGApp.exe' (CLR v4.0.30319: Min

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900