helo guys, i have a little problem here. i've always been using MS access as database to connect my vb.net applications. Now i've design a webpage in asp.net and i want to connect the login.aspx page with the sqlexpress provided in vb.net framework..can anyone help me with the steps?? just for test purpose i wrote the following code

Imports System.Data.SqlClient
Imports System.Configuration

Partial Class login
    Inherits System.Web.UI.Page

    Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
        Dim sqlCon As New SqlConnection("Data Source=alvin;Initial Catalog=Database.mdf")
        sqlCon.Open()
        MsgBox(sqlCon.State.ToString)
        sqlCon.Close()

    End Sub
End Class

Connect to an Access database using sqlclient is not possible. System.Data.OleDb is one of the best solution for any non-SQL Server database system.

EXAMPLE CODE on USING OLEDB IN VB.NET:

Imports System.Data.OleDb
Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader

/* use in page load event */
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;_
Data Source=C:\emp.mdb;")
'provider to be used when working with access database
cn.Open()
cmd = New OleDbCommand("select * from table1", cn)
dr = cmd.ExecuteReader
While dr.Read()
TextBox1.Text = dr(0)
TextBox2.Text = dr(1)
TextBox3.Text = dr(2)
' loading data into TextBoxes by column index
End While

If you have created a new DB in SQL Express and the table is in the 'app_data' folder in your project then something like this could work:

Dim conn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True")
        Dim sql As String = "SELECT * FROM tablename"
        Dim cmd As New SqlCommand(sql, conn)
        conn.Open()

you can then use this to fill a dataset or table in the same way you would have before

If you have created a new DB in SQL Express and the table is in the 'app_data' folder in your project then something like this could work:

Dim conn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True")
        Dim sql As String = "SELECT * FROM tablename"
        Dim cmd As New SqlCommand(sql, conn)
        conn.Open()

you can then use this to fill a dataset or table in the same way you would have before

Thx loads friend..it works great..am gonna work on it..thx again

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.