Locked How can I convert this VB6 code to visual basic 2010

  • Monday, June 25, 2012 12:46 PM
     
     

    Dim con As New ADODB.Connection
    Dim rs As New ADODB.Recordset

    con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " + App.Path + "\master.mdb;Persist Security info=false; jet OLEDB:database password=knhm89"

    rs.Open "select * from ledgers where status ='" & "CUST" & "'", con, 2, 2
            Do While Not rs.EOF
                If rs("party") = cbocust.Text Then
                    rs("amount") = rs("amount") - Val(txtttl.Text)
                    rs.Update
                End If
                rs.MoveNext
            Loop
            rs.Close

All Replies

  • Tuesday, June 26, 2012 10:12 AM
     
     Answered

    Hi,

    I would suggest to ask such a question inside a VB.Net or ADO.Net forum instead of this forum. This forum covers the Developer Documentation and MS Help System only.

    In general, you shoul dread about database access in general in VB.Net, becaus ethe technology has changed. (And in general you should do things different!)

    I see multiple things in your code:

    a) You are just changing values. So the normal database solution would be an UPDATE query. So something like UPDATE ledgers SET amount = amount + whatever WHERE status = YourStatus.

    Such a query can be directly issued using the classes OleDbConnection and OleDbCommand. (Please look them up on MSDN Library)

    b) If you really want to read data, modify it and then write the updated data back (For whatever reason - SQL  commands should be much faster), you could use the classes DataSet and OleDbDataAdapter. Maybe together with the OleDbCommandBuilder. The MSDn Library also contains small examples how to use these classes but I would recommend to take the time and read about ADO.Net so you learn and understand the technology behind. http://msdn.microsoft.com/en-us/library/e80y5yhx

    c) NEVER EVER build SQL Scripts through concatenation if not really required and be double carefull if you do it. You open your application to attacks, misbehaviours and a lot more problems e.g. regionalisation problems! Instead use the Parameter property of OleDbCommand! (Please see the MSDN Library for details!)

    I hope I was able to help you.

    With kind regards,

    Konrad

  • Saturday, June 30, 2012 12:31 PM
     
     

    Thank You dear... 

    Thank u for your valuable information.

    with love

    Sudheer Alappuzha

  • Wednesday, July 04, 2012 2:05 PM
     
     Proposed

    In addition to what Konrad told you, there is a forum dedicated to code conversion issues, here:

    http://social.msdn.microsoft.com/Forums/en-US/vbinterop/threads

  • Thursday, July 05, 2012 9:54 AM
     
     

    I moved the thread to the suggested forum.

    With kind regards,

    Konrad