Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

Unbound Access Data Source

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chip Pearson - 03 Jul 2007 22:50 GMT
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.

Signature

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

Mark Rae - 03 Jul 2007 23:25 GMT
> Do Until RecSet.EOF()
>    Debug.Print RecSet.Fields("Whatever").Value
>    RecSet.MoveNext
> Loop

Are you trying to use ADO instead of ADO.NET...?

If you're not doing any databinding, I would strongly advise not using any
of the DataSource objects at all.

Instead, just use ADO.NET to fetch a DataSet from your Jet database...
http://www.asp101.com/articles/jay/adodotnet/part3.asp

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Chip Pearson - 04 Jul 2007 01:19 GMT
>> Do Until RecSet.EOF()
>>    Debug.Print RecSet.Fields("Whatever").Value
>>    RecSet.MoveNext
>> Loop
>
> 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.

Signature

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

>> Do Until RecSet.EOF()
>>    Debug.Print RecSet.Fields("Whatever").Value
[quoted text clipped - 8 lines]
> Instead, just use ADO.NET to fetch a DataSet from your Jet database...
> http://www.asp101.com/articles/jay/adodotnet/part3.asp
Mark Rae [MVP] - 04 Jul 2007 02:22 GMT
>>> Do Until RecSet.EOF()
>>>    Debug.Print RecSet.Fields("Whatever").Value
[quoted text clipped - 12 lines]
> 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
               }
           }
       }
   }
}

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Juan T. Llibre - 05 Jul 2007 15:15 GMT
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 !

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
Mark Rae [MVP] - 05 Jul 2007 15:28 GMT
> Congratulations, Mark !

Aw shucks!

Gracias, jefe...

A sus ordines!

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Alvin Bruney [MVP] - 05 Jul 2007 16:39 GMT
I'll join in the chant. I think Mark is a great addition to the community!

Signature

Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
https://www.microsoft.com/MSPress/books/10933.aspx
OWC Black Book www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley

> 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,
[quoted text clipped - 8 lines]
> foros de asp.net, en español : http://asp.net.do/foros/
> ======================================

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.