Advertisement

09.16.2008 at 03:05AM PDT, ID: 23734533
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.9

OleDBConnection Update duplicates records in Access Table

Asked by ONEINVESTMENTS in .NET, Microsoft Access Database, Microsoft Visual Basic.Net

Tags: , , ,

I am trying to update an Access Table from VB.NET using OleDBConnection. It is working but every time it duplicated the records. Let's explain further.. If for example the table contains 1 row with the element "a", after adding a 1 row containing the element "b", the table elements are duplicated in a way that the table contains "a","a","b". If I try to add subsequentially the a row containing "c", the table will then contain "a","a","a","a","b","b","c" and so on... in other words that is already in the table is duplicated.
How can I avoid this? Here below is the code:
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:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
Public Function InsertCompany(ByVal dt As DataTable)
        Dim i As Integer
        Dim CustRow As DataRow
        Dim dr(5000) As DataRow
        Dim adapter As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM Customers", Conn)
 
        adapter.InsertCommand = New OleDbCommand("INSERT INTO Customers (SECID, BLOCK, ITEM, FY, V) VALUES(?, ?, ?, ?, ?);", Conn)
 
        adapter.InsertCommand.Parameters.Add("@SECIDBLP", OleDbType.VarChar, 50, "SECID")
        adapter.InsertCommand.Parameters.Add("@BLOCK", OleDbType.VarChar, 50, "BLOCK")
        adapter.InsertCommand.Parameters.Add("@ITEM", OleDbType.VarChar, 50, "ITEM")
        adapter.InsertCommand.Parameters.Add("@ITEM", OleDbType.Integer, 8, "FY")
        adapter.InsertCommand.Parameters.Add("@V", OleDbType.Double, 8, "V")
 
        adapter.AcceptChangesDuringFill = False
        adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
 
        Dim dcmID As New DataColumnMapping("SECID", "SECID")
        Dim dcmName As New DataColumnMapping("BLOCK", "BLOCK")
        Dim dcmITEM As New DataColumnMapping("ITEM", "ITEM")
        Dim dcmFY As New DataColumnMapping("FY", "FY")
        Dim dcmV As New DataColumnMapping("V", "V")
 
        Dim dtmTable As New DataTableMapping("Table", "Customers")
 
        dtmTable.ColumnMappings.Add(dcmID)
        dtmTable.ColumnMappings.Add(dcmName)
        dtmTable.ColumnMappings.Add(dcmITEM)
        dtmTable.ColumnMappings.Add(dcmFY)
        dtmTable.ColumnMappings.Add(dcmV)
 
        adapter.TableMappings.Add(dtmTable)
 
        Dim custDS As DataSet = New DataSet()
        adapter.Fill(custDS, "Table")
 
 
      
 
 
        For i = 1 To dt.Rows.Count - 1
            dr = dt.Select
            CustRow = custDS.Tables(0).NewRow()
            CustRow("SECID") = dr(i).Item(0).ToString
            CustRow("BLOCK") = dr(i).Item(1).ToString
            CustRow("ITEM") = dr(i).Item(2).ToString
            CustRow("FY") = dr(i).Item(3)
            CustRow("V") = dr(i).Item(4)
            custDS.Tables(0).Rows.Add(CustRow)
        Next i
 
        Try
            adapter.Update(custDS.GetChanges(), "Customers")
        Catch ex As Exception
            MessageBox.Show(ex.Message & " - " & ex.Source)
            Conn.Close()
        End Try
 
        custDS.AcceptChanges()
 
    End Function
[+][-]09.16.2008 at 08:18AM PDT, ID: 22489348

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 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.16.2008 at 08:36AM PDT, ID: 22489598

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 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.16.2008 at 08:40AM PDT, ID: 22489660

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 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.16.2008 at 09:13AM PDT, ID: 22490103

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 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.16.2008 at 09:17AM PDT, ID: 22490156

View this solution now by starting your 14-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: .NET, Microsoft Access Database, Microsoft Visual Basic.Net
Tags: Microsoft, VB.NET, 2005, Connect to Access 2003
Sign Up Now!
Solution Provided By: CodeCruiser
Participating Experts: 1
Solution Grade: B
 
 
 
Loading Advertisement...
20081112-EE-VQP-43 / EE_QW_2_20070628