[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[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!

6.1

VB6 not inserting entries in SQL database table with a Primary Key

Asked by Latzi_Marian in Visual Basic Programming, VB Database Programming, MS SQL Server

Tags: Microsoft, Visual Basic, VB6

Hi ,

I have the following code in VB6 which "dismantles a text file and writes it into a SQL database table.It worked fine for 2 months and suddenly stopped.Here's the code(part of it)
Private Sub Collect()
    Dim f As Integer
    Dim strSourceFile As String
    Dim iFirstColon As Integer
    Dim strTextLine As String
    Dim strFieldName As String
    Dim strValue As String
    Dim pcs As Integer
    Dim cn
    Dim RS
    Dim ipcs
    Dim Throughput
    Set cn = CreateObject("ADODB.Connection")
    Set RS = New ADODB.Recordset
   
   
        cn.Open "driver=SQL Server;server=(local);uid=;pwd=;database=CheckWeighers;"
        RS.Open "statex1", cn, adOpenDynamic, adCmdTable, adLockPessimistic
        strSourceFile = "C:/statex.txt"
            f = FreeFile
            Open strSourceFile For Input As #f
                Do Until EOF(f)
                    Line Input #f, strTextLine
                    Select Case Trim$(strTextLine)
                        Case "BLOCKBEGIN"
                            RS.AddNew
                        Case "BLOCKEND"
                        'On Error Resume Next 'This line is to Avoid duplicates  as I set Primary Key the Duration
                            RS.Update
                        Case Else
                            iFirstColon = InStr(strTextLine, ":")
                            strFieldName = Left$(strTextLine, iFirstColon - 1)
                            strValue = Mid$(strTextLine, iFirstColon + 1)
                            RS.Fields(strFieldName).Value = strValue
                    End Select
                Loop
            Close #f
         
        RS.Close
    cn.Close
    loadflexgrid
End Sub

so the SQL TABLE has a primary key on the Duration column.For my understanding if the recorset encounters a value for the duration the same as an existing one in SQL then it should skip the that entry and continue inserting the next entries.Unfortunately this is not happening.I am just wondering why??
What actuallythe story is that the text file is being updated every 2 minutes with new rows (might be 1 row or 100 rows) but the rest of the rows is still on the text file.What I would luike to achieve is to insert in SQL only the new rows in the text file.I am doing something wrong somewhere however I cannot explain why it worked up untill now.Maybe because I exhausted all the possible distinct values for the duration coulmn?An whatever Is coming in th etext file has got in the duration a value which is already present in the database.If I remove the primary key constraint from the table then the code will insert all the entries from the text file which will create plenty of duplicates.
What is wronmg??
[+][-]02/27/08 09:44 AM, ID: 20996308Accepted Solution

View this solution now by starting your 30-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: Visual Basic Programming, VB Database Programming, MS SQL Server
Tags: Microsoft, Visual Basic, VB6
Sign Up Now!
Solution Provided By: 3_S
Participating Experts: 3
Solution Grade: B
 
[+][-]02/26/08 11:34 PM, ID: 20992061Expert Comment

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

 
[+][-]02/26/08 11:43 PM, ID: 20992095Author Comment

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

 
[+][-]02/27/08 02:38 AM, ID: 20992861Expert Comment

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

 
[+][-]02/27/08 02:49 AM, ID: 20992920Author Comment

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

 
[+][-]02/27/08 03:32 AM, ID: 20993087Expert Comment

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

 
[+][-]02/27/08 04:14 AM, ID: 20993291Author Comment

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

 
[+][-]02/27/08 04:19 AM, ID: 20993336Expert Comment

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

 
[+][-]02/27/08 04:27 AM, ID: 20993378Author Comment

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

 
[+][-]02/27/08 09:47 AM, ID: 20996346Expert Comment

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

 
[+][-]02/27/08 02:58 PM, ID: 20999419Author Comment

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

 
[+][-]02/27/08 08:47 PM, ID: 21001290Expert Comment

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

 
[+][-]03/02/08 07:59 AM, ID: 21026422Expert Comment

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

 
 
Loading Advertisement...
20091118-EE-VQP-93 / EE_QW_2_20070628