-
Jan 24th, 2007, 01:01 AM
#1
Thread Starter
New Member
Type ADODB.Connection is not defined?
Hi all. Im a Delphi programmer by trade but I recently got a copy of Visual Studio 2005 so I could write some applications for PDAs.
Anyway, Im trying to connect to a MS SQL Server with ADO, and all the help Ive read tells me to do something like this :
Public Class Form1
Dim ADOCon As New ADODB.Connection
But I get an error saying Type ADODB.Connection is not defined
Any help would be much appreciated.
Thanks
-
Jan 24th, 2007, 01:20 AM
#2
Re: Type ADODB.Connection is not defined?
Welcome to VBF !
I think you need to include a reference to the ADODB object into your project...(I use this method in classic vb, not sure in vb 2005)
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
-
Jan 24th, 2007, 01:29 AM
#3
Thread Starter
New Member
Re: Type ADODB.Connection is not defined?
Yeah, Im not sure where though, or how really.
That line of code I included is the very first line.
-
Jan 24th, 2007, 02:55 AM
#4
Frenzied Member
Re: Type ADODB.Connection is not defined?
Nekron:
I think maybe this is what you need:
The following code creates a SqlConnection object, sets the
SqlConnection.ConnectionString property, and opens the connection.
VB Code:
Public Sub ConnectToSql()
Dim conn As New SqlClient.SqlConnection
' TODO: Modify the connection string and include any
' additional required properties for your database.
conn.ConnectionString = & _
"integrated security=SSPI;data source=SQL Server Name;" & _
"persist security info=False;initial catalog=northwind"
Try
conn.Open()
' Insert code to process data.
Catch ex As Exception
MessageBox.Show("Failed to connect to data source")
Finally
conn.Close()
End Try
End Sub
-
Jan 24th, 2007, 09:14 AM
#5
Re: Type ADODB.Connection is not defined?
Just to explain why AIS4U's example is what you should be using.. ADODB is the 'old' version which is designed for Classic VB (VB6 and earlier), whereas ADO.Net (as in that example) is designed for VB.Net (VB 200*).
-
Jan 24th, 2007, 07:20 PM
#6
Thread Starter
New Member
Re: Type ADODB.Connection is not defined?
Ok, thanks people.
I tried AIS4U's suggestion, and this is the declaration I had to make :
Code:
Dim Con As New System.Data.SqlClient.SqlConnection
Does anyone know why I had to do this? Seems too long-winded, but necessary unfortunately.
Also, is it possible to prompt for a Connection String at run-time? I was thinking, you know how you go through the wizard, and it prompts you to select a server, enter username and password, and select a database, is it possible to do this at run-time?
Thanks all.
-
Jan 24th, 2007, 07:30 PM
#7
Re: Type ADODB.Connection is not defined?
The ConnectionString is just a string in a particular format, so you can simply put in the relevant parts (like "SQL Server Name") using code which gets the values from a form (or anywhere you like!).
-
Apr 29th, 2009, 11:46 PM
#8
New Member
Re: Type ADODB.Connection is not defined?
i'm using visual basic 2008 express edition. i get that problem also. i need to export datagrid to excel. instead of ADODB.Connection, can i use Odbc.OdbcConnection()?
-
Apr 30th, 2009, 07:07 AM
#9
Re: Type ADODB.Connection is not defined?
You should not be using ADODB at all, as that is designed for VB6 (aka VB1998) and earlier.
Instead, you should be using ADO.Net (for VB2002 and later, aka VB.Net), which includes SqlConnection/OLEDBConnection/ODBCConnection.
In addition to AIS4U's example, you can find lots of useful info in the VB.Net section of our Database Development FAQs/Tutorials (at the top of this forum)
-
Jul 25th, 2014, 08:58 AM
#10
New Member
Re: Type ADODB.Connection is not defined?
Thanks.
Just replace
ADODB.Connection
with
System.Data.SqlClient.SqlConnection
with same references:
Imports System.Data.SqlDbType
Imports System.Data.SqlClient
and all works fine.
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
|