Can sombody please tell me where I am going wrong, please. I am trying to teach myself how to connect to a database that is not attached to my project.
I am using VB2010 Express with SQL express.
Here's the code I have;The form is simple, 1 single button on it. Press it and it is suppose to connect and display a message box, but I keep getting an error.Code:Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim con As New OleDb.OleDbConnection Dim dbProvider As String Dim dbSource As String Dim ds As New DataSet Dim da As OleDb.OleDbDataAdapter Dim sql As String dbProvider = "PROVIDER=Microsoft.SQLEXPRESS;" ' I've tried other versions of provider names such as, Provider=SQLEXPRESS. dbSource = "Data Source=C:\MarketPlaceDatabase.mdf" con.ConnectionString = dbProvider & dbSource con.Open() sql = "Select * From tblManagersTable" da = New OleDb.OleDbDataAdapter(sql, con) MsgBox("Database is now open") con.Close() MsgBox("Database is now closed") End Sub
Every project I have ever created has a SQL database attached to it so I a baffled to what is wrong. Also am wondering what the difference is between a MDF and MDB database extension. Mine always safe as a MDF, but all the articles I have read reference a MDB file.




Reply With Quote
