Advertisement

11.28.2007 at 03:51PM PST, ID: 22989314
[x]
Attachment Details

How to run Update query in Ms access from Vb.net application

Asked by Sivasan in Microsoft Visual Basic.Net, Databases Miscellaneous, Microsoft Access Database

Tags: access, query, update, run, ms

Hi There,
I have created an application using VB.net 2003 backend Ms access. On my Vb.net application I have a button and on the onclick event,  Im trying to run an Update query( UpdatePO)  (that updates data from one table to another table) that I have in my backend Ms access  database.

The problem is, it did run the update query the first time, but when I do it the next time, I get an ERROR
The changes you requested to the table were not successful becoz they would create duplicate values in the index, primary key or relationship. Change the data in the field that contain duplicate data,remove the index, or redefine to permit duplicate.

The same update query when I run from the ms access it has no problem any number of times I run it. It is not creating any duplicate as it's only an update, but for some reason my onclick event in Vb.net assumes it is going to create duplicate and not just update the existing data.
Im wondering if I some how have to make the code in my Vb.net understand to continueupdate on error.
Please find my onclick event below


Private Sub IMPBTN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IMPBTN.Click
       
        Try

            Dim conn As System.Data.OleDb.OleDbConnection

            Dim strConn As String

            strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"

            strConn &= "Data Source = F:\Rail.mdb;"

            conn = New System.Data.OleDb.OleDbConnection(strConn)



            Dim cmd As New System.Data.OleDb.OleDbCommand("UpdatePO", conn)

            cmd.CommandType = CommandType.StoredProcedure
                        conn.Open()

            cmd.ExecuteNonQuery()

            conn.Close()

        Catch ex As Exception
            MsgBox(ex.Message + vbCrLf + ex.Source & vbCrLf & vbCrLf & ex.StackTrace, MsgBoxStyle.Critical, "Error")
        End Try
    End Sub


How can I make it work .I will appreciate any help on this.
Thanks
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
Private Sub IMPBTN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IMPBTN.Click
        ' start1()
        Try
 
            Dim conn As System.Data.OleDb.OleDbConnection
 
            Dim strConn As String
 
            strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"
 
            strConn &= "Data Source = F:\Distribution & Logistics\Railcars\RailTruck Program\Rail.mdb;"
 
            conn = New System.Data.OleDb.OleDbConnection(strConn)
 
 
 
            Dim cmd As New System.Data.OleDb.OleDbCommand("UpdatePO", conn)
 
            cmd.CommandType = CommandType.StoredProcedure
           
            conn.Open()
 
            cmd.ExecuteNonQuery()
 
            conn.Close()
 
 
 
 
 
        Catch ex As Exception
                       MsgBox(ex.Message + vbCrLf + ex.Source & vbCrLf & vbCrLf & ex.StackTrace, MsgBoxStyle.Critical, "Error")
        End Try
    End Sub
[+][-]11.28.2007 at 04:51PM PST, ID: 20370486

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.28.2007 at 09:34PM PST, ID: 20371536

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]11.28.2007 at 09:44PM PST, ID: 20371566

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.29.2007 at 04:05AM PST, ID: 20372849

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.29.2007 at 08:28AM PST, ID: 20374879

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.29.2007 at 09:15AM PST, ID: 20375272

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.29.2007 at 01:58PM PST, ID: 20377737

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.29.2007 at 02:29PM PST, ID: 20377971

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual Basic.Net, Databases Miscellaneous, Microsoft Access Database
Tags: access, query, update, run, ms
Sign Up Now!
Solution Provided By: LSMConsulting
Participating Experts: 2
Solution Grade: A
 
 
[+][-]11.29.2007 at 03:32PM PST, ID: 20378439

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.30.2007 at 01:20PM PST, ID: 20385393

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628