RSS

OleDb – Simple Database Databinding

Sun, Aug 17, 2008

ASP.NET, Code

If you do not have MS SQL installed (Why not? The Express version is free!) or prefer the portability MS Access provides then you might want to learn how to create an OleDbConnection, part of the System.Data.OleDb namespace, as opposed to SqlConnection which is part of the System.Data.SqlClient namespace. Here is a quick example of how an OleDbConnection string is used.

Dim objConn As OleDbConnection
Dim objRDR As OleDbDataReader
Dim objCmd As OleDbCommand
objConn = New OleDbConnection( _
“Provider=Microsoft.ACE.OLEDB.12.0;Data Source=” & _
“E:Documentsdatabasestest.accdb”)
objCmd = New OleDbCommand(”SELECT [first], [last] FROM [names]“, objConn)
objConn.Open()
objRdr = objCmd.ExecuteReader()
GridView1.DataSource = objRdr
GridView1.DataBind()
Share and Enjoy:
  • Facebook
  • Twitter
  • MySpace
  • Digg
  • del.icio.us
  • Google Bookmarks
  • Yahoo! Buzz
, ,

Comments are closed.