|
-
Jul 4th, 2007, 05:53 PM
#1
Thread Starter
Hyperactive Member
[2005] (Migration) CNN.Execute(VB6) equivalent in VB2005
Hi.
I'm very new to vb2005. I'm migrating from VB6 to VB2005.
In VB6, I've been using ADODB.connection, In VB2005 I'm using SqlClient.SqlConnection.
My question is: what is the equivalent expression to "CNN.Execute (strSQL)".
(My old code: )
Code:
Public CNN As New ADODB.Connection
Public Function ExecuteSQL(strSQL As String)
CNN.Execute (strSQL)
End Function
Thank you
-
Jul 4th, 2007, 06:02 PM
#2
Re: [2005] (Migration) CNN.Execute(VB6) equivalent in VB2005
Use the ExecuteReader function of the OleDbCommand object
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 4th, 2007, 06:19 PM
#3
Thread Starter
Hyperactive Member
Re: [2005] (Migration) CNN.Execute(VB6) equivalent in VB2005
I will have to do somehting like this?
Code:
Dim x As New OleDb.OleDbCommand
Dim xx As New OleDb.OleDbConnection
This is my actual code. Should I change something?
Code:
Public rs As New SqlClient.SqlDataAdapter
Public cnn As New SqlClient.SqlConnection
Public Const ID_DB As String = "GesProj"
Public Const server As String = "SERVER_000001"
Public Const user As String = "SA"
Public Const Password As String = "SA"
Public Sub Conect()
Try
cnn.ConnectionString = "Data Source=" & server & ";Initial Catalog=" & ID_DB & ";Persist Security Info=True;User ID=" & user & ";Password=" & Password
Exit Sub
Catch err As Exception
MessageBox.Show("Erro: " & err.Message, "No connection", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Public Sub Disconect()
Try
cnn.Close()
cnn = Nothing
Exit Sub
Catch err As Exception
MessageBox.Show("Erro: " & err.Message, "No connection", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
This is my code in need of upgrade:
Code:
Public Sub ExecuteSQL(ByVal strSQL As String)
'OLD VB6 CODE
cnn.exeucte strSQL
End Sub
-
Jul 4th, 2007, 06:22 PM
#4
Re: [2005] (Migration) CNN.Execute(VB6) equivalent in VB2005
No quite. Here is one example...
Code:
Dim cs As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\VB-Guru\RobDog888.mdb;Jet OLEDB:Database Password=Meow;"
Dim con As New OleDb.OleDbConnection(cs)
con.Open()
Dim cmd As New OleDb.OleDbCommand("SELECT Field2 FROM Table1 WHERE Field2 = 'Meow'", con)
Dim dr As OleDb.OleDbDataReader = cmd.ExecuteReader()
'etc
Are you trying to execute query code or action code?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 4th, 2007, 07:04 PM
#5
Thread Starter
Hyperactive Member
Re: [2005] (Migration) CNN.Execute(VB6) equivalent in VB2005
In VB6, what I was doing was, basically, 2 functions:
1st -execute SQL (like Insert, Update and Delete instructions)
This function has a parameter StrSQL.
2nd -return an ADODB.RecordSet to a function (Select instructions) named OpenRS
With OpenRS, I could bind combobox, DataGrid, etc
Now I'm a little lost upgrading may apps.
By what I've been seeing, people uses SqlClient.SqlDataAdapter and SqlClient.SqlConnection to connect to SQL Databases.
What is the most appropriate to use:
SQLClient, OLEDB or even reference ADODB ActiveX Component from VB6?
-
Jul 5th, 2007, 12:20 AM
#6
Re: [2005] (Migration) CNN.Execute(VB6) equivalent in VB2005
Forget VB 6 ADO. Its not at all the same in ADO.NET
There are no recordsets, only datasets and datatables.
SqlClient class is only for use with SQL Server. Its optimized especially for SQL Server. Access or other generic databases use OleDB class.
Bottom line: ADO.NET <> classic (VB 6) ADO
For more info you may want to go through a tutorial or faq link this one...
http://vbforums.com/showthread.php?t=466658
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 5th, 2007, 07:42 AM
#7
Thread Starter
Hyperactive Member
Re: [2005] (Migration) CNN.Execute(VB6) equivalent in VB2005
I'm using SQL Server 2000 Database
Am I in a good way with this code?
Code:
Public CNN As New SqlClient.SqlConnection
Public rs As New SqlClient.SqlDataAdapter
Public Const ID_DB As String = "GesProj"
Public Const server As String = "Turion\PRIMAVERA"
Public Const user As String = "SA"
Public Const Password As String = "SA"
Public Sub Conect()
Try
CNN.ConnectionString = "Data Source=" & server & ";Initial Catalog=" & ID_DB & ";Persist Security Info=True;User ID=" & user & ";Password=" & Password
Exit Sub
Catch err As Exception
MessageBox.Show("Erro: " & err.Message, "Sem conexão", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Public Sub Disconect()
Try
CNN.Close()
CNN = Nothing
Exit Sub
Catch err As Exception
MessageBox.Show("Erro: " & err.Message, "Sem conexão", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
-
Jul 5th, 2007, 08:31 AM
#8
Thread Starter
Hyperactive Member
Re: [2005] (Migration) CNN.Execute(VB6) equivalent in VB2005
By the way, I'm using VB2005 Express.
-
Jul 5th, 2007, 09:03 AM
#9
Thread Starter
Hyperactive Member
Re: [2005] (Migration) CNN.Execute(VB6) equivalent in VB2005
Now I'm getting this error:
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
I've tested the connection in VB6 and everything works great.
Help me please
-
Jul 5th, 2007, 01:10 PM
#10
Re: [2005] (Migration) CNN.Execute(VB6) equivalent in VB2005
Thats the same code you posted earlier. Its not valid as it only sets a connectionstring. Have you even tried my code?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|