I would like to open a access database using VB.NET. However i want to be able to connect to a Access database at runtime and have this appear in the datagrid. how do you do this?

I would also like to create a database using VB.Net and have fields weight,comment inserted into it, and then for this to appear in the same datagrid. the option to save this new database would be needed.

Any help wil appreciated

how to connect to the Database in datagride via the vb.Net2003

Vb.Net 2005 Connectivity. I think,It totally same in 2003.

Imports System.Data.SqlClient
Public Class Form1
Dim con As New SqlConnection("Data Source=ABC-17372608800\SQLEXPRESS;Database=sonia;integrated Security=true")
Dim da As SqlDataAdapter
Dim ds As New DataSet

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
da = New SqlDataAdapter("select * from student", con)
da.Fill(ds, "student")
DataGridView1.DataSource = ds.Tables("student")
End Sub
End Class

I would like to open a access database using VB.NET. However i want to be able to connect to a Access database at runtime and have this appear in the datagrid. how do you do this?

[second request removed]

Any help wil appreciated

Hi, while you did not specify which version of Microsoft Access, you probably using pre 2007 version. There is a website http://www.connectionstrings.com that has examples for how to connect to pretty much anything in existance.

Here is the link for the Access connection string: http://www.connectionstrings.com/?carrier=access

Hopefully, you are using Visual Studio 2005, so all you need to do is drop a OpenFileDialog component on a form, otherwise, if you are using Visual Studio 2003, you may have to build the UI yourself. Once your user locates the Access file, simply update the connectection string.

Hope this helps,

Johnny

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.