Protected Sub Page_Load(sender As Object, e As System.EventArgs)
Dim strDatabaseNameAndLocation As String
strDatabaseNameAndLocation = Server.MapPath("shop.mdb")
Dim strSQLCommand As String
strSQLCommand = "SELECT Product.* FROM Product ORDER BY Product.productID ASC;"
Dim objOleDbConnection As System.Data.OleDb.OleDbConnection
objOleDbConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0; Data Source=" & strDatabaseNameAndLocation)
objOleDbConnection.Open()
Dim objOleDbCommand As System.Data.OleDb.OleDbCommand
objOleDbCommand = New System.Data.OleDb.OleDbCommand(strSQLCommand, objOleDbConnection)
Dim objOleDbDataReader As System.Data.OleDb.OleDbDataReader
objOleDbDataReader = objOleDbCommand.ExecuteReader()
gdvproducts.DataSource = objOleDbDataReader dvproducts.DataBind() objOleDbConnection.Close()
End Sub
Please note. You can avoid repeating System.Data.OleDb in every line if you add the namespace "System.Data.OleDb" to the page.
Kindly mark this post as "Answer", if it helped you.
basheerkal
Star
10672 Points
2426 Posts
Re: Images in datagrid
Apr 28, 2012 02:14 AM|LINK
This is enough. no need of a Table
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Dim strDatabaseNameAndLocation As String strDatabaseNameAndLocation = Server.MapPath("shop.mdb") Dim strSQLCommand As String strSQLCommand = "SELECT Product.* FROM Product ORDER BY Product.productID ASC;" Dim objOleDbConnection As System.Data.OleDb.OleDbConnection objOleDbConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0; Data Source=" & strDatabaseNameAndLocation) objOleDbConnection.Open() Dim objOleDbCommand As System.Data.OleDb.OleDbCommand objOleDbCommand = New System.Data.OleDb.OleDbCommand(strSQLCommand, objOleDbConnection) Dim objOleDbDataReader As System.Data.OleDb.OleDbDataReader objOleDbDataReader = objOleDbCommand.ExecuteReader() gdvproducts.DataSource = objOleDbDataReader dvproducts.DataBind() objOleDbConnection.Close() End SubPlease note. You can avoid repeating System.Data.OleDb in every line if you add the namespace "System.Data.OleDb" to the page.
(Talk less..Work more)