Unbound Access Data Source

C

Chip Pearson

I'm sure I'm missing something simple, but I've hit a brick wall. I'm
creating an ASP.NET 2.0 web site in VS2005 (VB.NET) and need to read data
from an Access database without attaching it to any UI control. I've dropped
an AccessDataSource control named AccessGetDescription on my aspx page and
configured the data source with an SQL SELECT statement. Now, how in code
do I loop through the returned records? Here's what I have so far:

Dim IEnum As IEnumerable
Dim ThisFile As String
Dim ???? As ????
ThisFile = "Whatever.xls"
With Me.AccessGetDescription
.SelectCommandType = SqlDataSourceCommandType.Text
.SelectCommand = "SELECT Description FROM TableName WHERE FileName =
ThisFileName"
.SelectParameters.Add("ThisFileName", ThisFile)
IEnum = .Select(DataSourceSelectArguments.Empty)
For Each ???? In ????
MyDesc = ???.Fields("Description").ToString()
Next ???
End With

What goes after the .Select method and how are the variables declared to
loop through all the records? I'm used to ADO where you can do a

Do Until RecSet.EOF()
Debug.Print RecSet.Fields("Whatever").Value
RecSet.MoveNext
Loop

I can't get this to work in ASP.NET 2.0.

Any suggestions would be greatly appreciated. Thank you very much.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)
 
C

Chip Pearson

Do Until RecSet.EOF()
Are you trying to use ADO instead of ADO.NET...?

That code was just an example of what I am used to doing (in VB6 and VBA),
not what I'm doing now. Yes, I'm using ADO.NET. The link you posted was
interesting, but it still relied on binding the data source to a control, in
this case the DataGrid. I do NOT want to bind to any control. All I want to
do is a FOR loop iterating through the returned records one at a time,
examining the various fields of each record.

I would be very grateful if you could post some working code that iterates
through the result records of a SELECT without (!) binding to any control.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)
 
M

Mark Rae [MVP]

That code was just an example of what I am used to doing (in VB6 and VBA),
not what I'm doing now. Yes, I'm using ADO.NET. The link you posted was
interesting, but it still relied on binding the data source to a control,
in this case the DataGrid. I do NOT want to bind to any control. All I
want to do is a FOR loop iterating through the returned records one at a
time, examining the various fields of each record.

I would be very grateful if you could post some working code that iterates
through the result records of a SELECT without (!) binding to any control.

There are *heaps* of examples of how to do this in MSDN and on Google etc,
but...

string strConnectionString = "<...connection string to your Jet
database...>";
string strSQL = "<...SELECT * FROM Table WHERE This = That...">;
using (OleDbConnection objOleDbConnection = new
OleDbConnection(strConnectionString))
{
objOleDbConnection.Open();
using (OleDbCommand objOleDbCommand = new OleDbCommand(pstrSQL,
objOleDbConnection))
{
using (OleDbDataAdapter objDA = new
OleDbDataAdapter(objOleDbCommand))
{
using (DataSet objDataSet = new DataSet())
{
objDA.Fill(objDataSet);
objOleDbConnection.Close();
foreach (DataRow objRow in objDataSet.Tables[0].Rows)
{
// objRow["Field1"].ToString();
// objRow["Field2"].ToString();
// objRow["Field3"].ToString();
// etc
}
}
}
}
}
 
J

Juan T. Llibre

Please join me in congratulating Mark Rae, who was just named ASP.NET MVP
for the excellence and community spirit he has shown in his prolific,
and technically accurate, answers which have helped hundreds of frequenters
to the microsoft.public.dotnet.framework.aspnet newsgroup.

Congratulations, Mark !




"Mark Rae [MVP]" <[email protected]> wrote
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top