Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating an ADO Connection with C#

Status
Not open for further replies.

JohnGreiner

Programmer
May 10, 2002
8
US
I have been using VB for a few years, but this C# thing is really killing me. I am trying to connect to a SQL Server Database using ADO. I have already added a Reference to ADO 2.7 Libraries, and I figured out how to declare my Connection Object and my Recordset Object. I cannot figure out how to set up and open a connection. Also, how do I send a SQL statement to return a Recordset?

Here is what I have finished so far:

public class Form1 : System.Windows.Forms.Form
{
public ADODB.Connection EngDatabase;

public Form1()
{
InitializeComponent();

EngDatabase.Provider = "sqloledb";
EngDatabase.DefaultDatabase = "Engineering";

I keep getting an Error. I am trying to Connect to a Server Call 'C629797-a' the Database is "Engineering" and I am using Sql Server.

Any Help would be appreciated.
 
This thread732-95012 might get you started.

Chip H.
 
Thanks, but I was looking for the Connection String information.
 
The connection string with ADODB should be the same as the one you used in VB6.

Try
Code:
EngDatabase.Open("Provider=sqloledb;Data Source=Engineering;")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top