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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ConnectionString with .mdf file

Status
Not open for further replies.

pencil151

Technical User
Jan 31, 2008
8
US
Hello I'm trying to create a connection string to a AddressBook.mdf file. This file only has 1 table which is "Addresses." This file is located in the root of C:\ Here's what I have:

public Form1()
{
InitializeComponent();
string conn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\AddressBook.mdf";
OleDbConnection myConn = new OleDbConnection();
myConn.ConnectionString = conn;
OleDbDataAdapter daAddress = new OleDbDataAdapter("SELECT * FROM Addresses", myConn);
DataSet dsAddress = new DataSet();
daAddress.Fill(dsAddress, "Addresses");
}


I get an error on daAddress.Fill(dsAddress, "Addresses"); it says "unrecognized database format 'c:\AddressBook.mdf'.

This connection string works on .mdb files, but how do I create a connection string to a .mdf file?
 
Oh I'm just practicing with C# books "Deitel C# for programmers." In this exercise it has an .mdf. I drop the tables into the "form" but when I do this it automatically creates the adapter, binding, and dataGrid. For learning purposes I wanted to create those items manually but I'm already stuck. =\
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top