Results 1 to 6 of 6

Thread: [2008] trouble updating database!!

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    255

    [2008] trouble updating database!!

    Hello,

    I have a strange problem. I have written the following code to insert details into my database the user can enter a quantity and the routine will run until
    the vairable check = the vairable quantity.

    now what is wierd is that it works fine but one it has entered record 2084, 2184, 2284 (anything ending in 84 basically) it stops working.
    It stops returning the last value in the serial number field, it returns the previous and therefore wont insert into the database anymore as it will create a duplicate value in the primary key!

    can anyone thing what is making it screw up?????

    here's my code..........

    PHP Code:
    Dim last As Integer

            Dim SerialNo 
    As Integer

            Dim check 
    As Integer 0

            
    Do Until check qty

                check 
    check 1

                DT8000 
    DB.GetTable("Select Last (serialNo) From Shipped")

                
    DR8000 DT8000.Rows(0)

                
    last DR8000("expr1000")

                
    SerialNo last 1

                DB
    .Insert("insert into Shipped (serialNo, Family, Model, SDate)   Values (" serialNo ", '" Family "', '" model "', '" Year "') "))

            
    Loop 
    any help will be much appreciated, i am baffled!

    cheers,

    Iain

  2. #2
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: [2008] trouble updating database!!

    Is that VB.NET code? What is DT8000's, DR8000's and DB's data type?
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  3. #3
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: [2008] trouble updating database!!

    What database are you using? I'm not familiar with the 'last' keyword.
    Use a parameterized command to prevent sql injection. Also setup your serialno as an identity column so you don't have to keep track of the last serial number. Here is an example for sql server
    Code:
            Dim insertSql As String = _
            "insert into Shipped ( Family, Model, SDate) " & _
            "Values ('@family', '@model', '@year')"
    
            For check As Integer = 1 To qty
    
    
                Dim con As New Data.SqlClient.SqlConnection("connection string")
                Dim cmd As New Data.SqlClient.SqlCommand(insertSql)
                cmd.Parameters.AddWithValue("@family", family)
                cmd.Parameters.AddWithValue("@model", model)
                cmd.Parameters.AddWithValue("@year", Year)
                cmd.Connection = con
    
                con.Open()
                cmd.ExecuteNonQuery()
                con.Close()
    
            Next
    I would also look at creating a quantity column, so you make one insert.
    That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma

    Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    255

    Re: [2008] trouble updating database!!

    i have this dll called sqlops that the college gave me
    so i reference that in my program.
    so
    dim DB as new sqlops.MSAccess("C:/mydatabase.mdb")
    dim dt8000 as datatable
    dim dr8000 as datarow

    the last you are onabout is an SQL command that will return the last record of a table, in my case i am returning the last reorded value in the SerialNo column of the Shipped table.

    I have never used anything else to connect VB.net to a database as my tutor has only showed us the way with SQLOPS, i'm a bit annoyed with them for not teaching us the way everyone else does it!

  5. #5
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: [2008] trouble updating database!!

    Well, I guess if you're using a predifined data layer, there's not much you can do. Try changing your query to
    Code:
    Select MAX(serialNo) From Shipped
    That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma

    Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    255

    Re: [2008] trouble updating database!!

    ok i'll have a go at that!
    thanks everyone for your suggestions!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width