Click here to Skip to main content
15,891,745 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I had created a vb.net application which is able to run well in windowsXP.

I'd just tried to install it into windows7 and an error occured in a saving method.
Other method is ok except for this.

What should be the cause of it? codes or windows?
If anyone knows just tell me.

The code of this method is below (My coding may not clean ^^)
VB
Dim de As OleDbDataReader
        Dim cn As OleDbConnection = New OleDbConnection(MySTR)
        Dim cmd As OleDbCommand
        Dim cmdStr As String = ""
        Dim dt As DataTable = New DataTable
        Dim working_info_id As Integer
        Dim state As String = ""
        Dim row As Integer = 0
        Dim mbresult As MsgBoxResult
        Dim emp_id As Integer = 0
        'Dim dt As Date = dtworkingInfo.Value.Date.Day & "/" & dtworkingInfo.Value.Date.Month & "/" & dtworkingInfo.Value.Date.Year-543
        mbresult = MsgBox("กรณีที่คุณต้องการบันทึกข้อมูลนี้ กรุณากดปุ่ม 'OK'" & vbCrLf & _
                      "ถ้าไม่ต้องการ กรุณากดปุ่ม'Cancel'", vbOKCancel, "!แจ้งเตือน")
        'Try


        progressbarUpdate.Maximum = gvemployee.Rows.Count * 10

        Select Case mbresult
            Case vbOK
                Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
                progressbarUpdate.Visible = True

                progressbarUpdate.Value = 10
                For i As Integer = 0 To gvemployee.Rows.Count - 2
                    If i <= (gvemployee.Rows.Count * 10) Then
                        progressbarUpdate.Value = (i * 10)
                    End If

                    If gvemployee.Rows(i).Cells(4).Value = True Then
                        state = "ทำงาน"
                        row = 4
                    ElseIf gvemployee.Rows(i).Cells(5).Value = True Then
                        state = "ลาป่วยครึ่งวัน"
                        row = 5
                    ElseIf gvemployee.Rows(i).Cells(6).Value = True Then
                        state = "ลาป่วยเต็มวัน"
                        row = 6
                    ElseIf gvemployee.Rows(i).Cells(7).Value = True Then
                        state = "ลากิจครึ่งวัน"
                        row = 7
                    ElseIf gvemployee.Rows(i).Cells(8).Value = True Then
                        state = "ลากิจเต็มวัน"
                        row = 8
                    ElseIf gvemployee.Rows(i).Cells(9).Value = True Then
                        state = "ขาด"
                        row = 9
                    Else
                        cmd = New OleDbCommand("select working_state from tb_working_info where emp_id=" & gvemployee.Rows(i).DataBoundItem("emp_id").ToString & " and working_date=#" & dtworkingInfo.Value.Date.Month & "/" & dtworkingInfo.Value.Date.Day & "/" & dtworkingInfo.Value.Date.Year & "#", cn)
                        de = cmd.ExecuteReader
                        If de.Read Then
                            state = de("working_state")
                        Else
                            state = "-"
                        End If

                    End If
                    emp_id = gvemployee.Rows(i).DataBoundItem("emp_id")
                    de = getState(emp_id)

                    Threading.Thread.Sleep(10)
                    'Try
                    If de.Read Then
                        id = de("emp_id")
                        working_info_id = de("id")
                        cmdStr = "update tb_working_info set emp_id=" & emp_id & ",working_date=#" & dtworkingInfo.Value.Date.Month & "/" & dtworkingInfo.Value.Date.Day & "/" & dtworkingInfo.Value.Date.Year & "#,working_state='" & state & "' where id=" & working_info_id
                    Else
                        cmdStr = "insert into  tb_working_info (emp_id,working_date,working_state)  values (" & emp_id & ",#" & dtworkingInfo.Value.Date.Month & "/" & dtworkingInfo.Value.Date.Day & "/" & dtworkingInfo.Value.Date.Year & "#,'" & state & "')"
                    End If
                    With cn
                        If .State = ConnectionState.Open Then .Close()
                        .ConnectionString = MySTR
                        .Open()
                    End With
                    cmd = New OleDbCommand(cmdStr, cn)
                    If state <> "" Then
                        cmd.ExecuteNonQuery()
                    End If
                    state = ""
                                        Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
                    Threading.Thread.Sleep(10)
                Next
                cancelselectedCell = 0


                progressbarUpdate.Value = gvemployee.Rows.Count * 10

                cancelselectedCell = 0
                progressbarUpdate.Visible = False
                Dim dr1 = retrieveEmpInfo()
                Dim da As DataTable = New DataTable
                da.Load(dr1)
                gvemployee.DataSource = da
                Me.Cursor = System.Windows.Forms.Cursors.Default
            Case vbCancel
                cancelselectedCell = 0
                Dim dr1 = retrieveEmpInfo()
                Dim da As DataTable = New DataTable
                da.Load(dr1)
                gvemployee.DataSource = da
                (Me.PayrollDataSet.tb_employee, "#" & dtworkingInfo.Value.Date & "#", "#" & dtworkingInfo.Value.Date & "#", "#" & dtworkingInfo.Value.Date & "#")
        End Select
        Dim countemp As OleDbDataReader = countEmployee()
        If countemp.Read Then
            count = countemp("countEmp")
        End If
        Dim dr As OleDbDataReader = checkWorkingInfo() 'ตรวจสอบว่าเคยลงข้อมูลวันที่นี้หรือยัง
        If Not dr.Read Then
            cbcheckAll.Enabled = True
        Else
            cbcheckAll.Enabled = False
        End If
        progressbarUpdate.Visible = False


Apology for an unconvinient..
this is the error message http://image.free.in.th/z/im/jdddd.jpg[^]
thanks for helping everyone.
Posted
Updated 22-May-11 22:15pm
v4
Comments
Sergey Alexandrovich Kryukov 23-May-11 0:11am    
You need to show the exception dump and indicate related code line(s). Where is your "error in saving method", message, inner exception, stack?
--SA
Dave Kreskowiak 23-May-11 0:45am    
And what's with the BS Thread.Sleep calls?? They do nothing for you here.

Without knowing what the expected behavior is and what this code is actaully doing and/or anyn error messages, it's extremely difficult to tell you what is wrong.
Karwa_Vivek 23-May-11 2:59am    
Can you State the Error Message
while Saving in Win-7
Dalek Dave 23-May-11 3:34am    
Edited for Grammar, Syntax and Readability.
jack_th 23-May-11 4:04am    
sorry everyone! this is error pics..(http://image.free.in.th/z/im/jdddd.jpg)

Most Probably It must be the
Permission related issue.
In win 7 Access database becomes write
proteced .And it restricts user to add or modify into
the database.
You should give the user all Permissions.
If my Assumtions are true.Visit the link [^]
Follow the Steps and then try to Save
 
Share this answer
 
v2
Comments
Dalek Dave 23-May-11 3:34am    
Certainly possible.
jack_th 23-May-11 4:05am    
Thanks, i will try that.
Karwa_Vivek 23-May-11 5:17am    
that's fine ..after viewing the Pic
i can assure you..this will definitely
solve your Problem
Dave Kreskowiak 23-May-11 7:45am    
You do NOT give a user all permissions. You give them just enough to do what they need to do. It's entirely possible the database is in the wrong folder, such as something under Program Files.

Giving a user the Full Control permission to the file/folder is just begging for trouble.
Karwa_Vivek 23-May-11 8:09am    
you Can try This .
By putting the database
anywhere Else also.It will not work until you give the user Full Control Specially in windows-7 and Vista.
you must have to give the full control on the drive where the Database resides.If not Satisfied with my Comment Search Google..you will get the Answer.
visit- http://www.tekscan.com/updateable-query
or http://www.mindplay.com/KnowledgeBase/ViewArticle.aspx?id=31
Based on the error, permissions are not the problem. Your problem seems to be that you are trying to use a query that either didn't return a primary key or are trying to use a query in the wrong place. For example, the code is trying to execute an Update command and you supplied a SELECT query for it's SQL.
 
Share this answer
 
Comments
Karwa_Vivek 23-May-11 7:49am    
I disagree.
I personally had passed through this problem
and finally I have to work on Permissions
Here it is nothing to do with codes.
Dave Kreskowiak 23-May-11 9:46am    
Down-vote me all you want. Just because you ran into the error message once does NOT mean that there is one and only one cause of the problem, being the one you faced.
jack_th 23-May-11 21:57pm    
Thanks for you all comments and discussions on this question. I've aready fixed it. And actually the problem was from permission as karwavivek had told. So thank you very much to karwavivek ^^.
But also Thank you alot to Dave Kreskowiak. Your solution also great interm of Observations for next future problem.
Karwa_Vivek 24-May-11 1:43am    
some times, what you See
is not actually there......

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