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.Recordsetcon.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- Moved by Konrad NeitzelMicrosoft Community Contributor Thursday, July 05, 2012 9:52 AM VB to VB.Net Upgrade Question (From:Developer Documentation and Help System)
All Replies
-
Tuesday, June 26, 2012 10:12 AM
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
- Proposed As Answer by pvdg42MVP Wednesday, July 04, 2012 2:03 PM
- Marked As Answer by Mark Liu-lxfModerator Friday, July 06, 2012 7:35 AM
-
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
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
- Proposed As Answer by Konrad NeitzelMicrosoft Community Contributor Wednesday, July 04, 2012 2:10 PM
-
Thursday, July 05, 2012 9:54 AM
I moved the thread to the suggested forum.
With kind regards,
Konrad

