Reading MS Access Tables

  • Thread starter Thread starter princeh8
  • Start date Start date
P

princeh8

I can connect to SQL Server and read any table data but
can't do so with MS Access 2000 (9.0.2720)

Here is a sample code.

on the webForm.aspx page I have the following web server
control:

<asp:dropdownlist id="roomList" runat="server">
</asp:dropdownlist>

In the webForm.aspx.cs file (the file behind the scenes)
I have the following code..

As a class level variable I have the following:
OleDbConnection conn;
DataSet ds;
OleDbDataAdapter daRooms;


Inside the InitializeComponent() method, I initialize the
connection string as follows:

this.conn = new OleDbConnection();
this.conn.ConnectionString
= "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\\Inetpub\\wwwroot\\WebApp\\mydatabase.mdb"


Now within the Page_Load() event handler I have..

conn.Open();
daRooms = new OleDbDataAdapter("SELECT * FROM Rooms",
conn);
daRooms.Fill(ds, "Rooms");
roomList.DataSource = ds.Tables["Rooms"];

if(!this.IsPostBack){
this.DataBind();
}
conn.Close();




When I run the application, instead of seeing the room
names within the <asp:dropDownList> control, I see the
following:

System.DataRow.DataView


I see one such line for each room name that is in the
database table, Rooms

Can someone please tell me why? What am I doing wrong?

thanks,
Prince
 
Can someone please tell me why? What am I doing wrong?

Your DropDownList has several properties you need to set.

DataMember: the name of the table you want to bind the list to. This is
required only if your DataSource contains multiple tables.

DataTextField: the name of the field within the bound table you wish to
display.

DataTextFormatString: the formatting picture to use in when displaying
data from the field specified in DataTextField

DataValueField: the name of the field which provides the value
associated with each text entry in the DropDownList.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
 
Back
Top