Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Do Until, For Each, EOF - SQL in ASP.NET (VB)

Posted on 2009-05-12
11
Medium Priority
?
699 Views
Last Modified: 2013-11-26
I want to query an SQL table for all instances of a particular field. (i.e. SELECT COUNT(*) FROM myTable where ID = '187')

Then I want to cycle through each record and do something based on the data. (For Each, EOF/BOF, etc.)

What is the best way to go about doing this in ASP.NET(VB)?
0
Comment
Question by:Mike Miller
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
11 Comments
 
LVL 5

Accepted Solution

by:
Aanvik earned 1000 total points
ID: 24366893

    Dim strSQL As String = "SELECT * FROM myTable where ID = '187'"
    Dim Connection As New OleDbConnection("PROVIDER=....")
    Dim DA As New OleDbDataAdapter(strSQL, Connection)
    Dim DS As New DataSet
 
    DA.Fill(DS, "Codes")
 
    Dim dt As New DataTable = DS.Tables(0)
    Dim dr As DataRow
    For Each dr In dt.Rows()
       'Do whatever you want to do with each record.
    Next

Open in new window

0
 

Author Comment

by:Mike Miller
ID: 24367018
Ok that looks good. So how would i reference what is in the columns?

Like

Label1.text = ??????? for whatever is in the 3rd column
0
 
LVL 7

Expert Comment

by:urir10
ID: 24367069
Label1.text = dt(0)   for the first column
or Label1.text = dt("name of column")
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:Mike Miller
ID: 24367334
I'm getting "End of statement expected" on:
Dim dt As New DataTable = DS.Tables(0)

and

Name dt is not declared on:
 For Each dr In dt.Rows()
        Dim strSQLlsd As String = "SELECT * FROM tblMultiTours where ID like '" & Label1.Text & "'"
        Dim Connection As New Data.OleDb.OleDbConnection("Data Source=ussrm-netsql\netdata;" & _
      "Initial Catalog=Employee;" & _
      "Integrated Security=SSPI")
        Dim DA As New Data.OleDb.OleDbDataAdapter(strSQLlsd, Connection)
        Dim DS As New Data.DataSet
        DA.Fill(DS, "Codes")
        Dim dt As New DataTable = DS.Tables(0)
        Dim dr As Data.DataRow
        For Each dr In dt.Rows()
            
        Next

Open in new window

0
 
LVL 5

Expert Comment

by:Aanvik
ID: 24367360
Change DA.Fill(DS, "Codes") to  DA.Fill(DS)
0
 
LVL 7

Expert Comment

by:urir10
ID: 24367381
Sorry i meant dr not dt
0
 

Author Comment

by:Mike Miller
ID: 24367505
DA.Fill(DS)

gives me the same 2 errors
0
 
LVL 7

Expert Comment

by:urir10
ID: 24367604
Do you have the right Namespaces included?

Imports System.Data
Imports System.Data.OleDb
0
 

Author Comment

by:Mike Miller
ID: 24367638
Yes
0
 
LVL 7

Assisted Solution

by:urir10
urir10 earned 1000 total points
ID: 24367923
try this instead:
            Dim dt As New DataTable
            dt = DS.Tables(0)
0
 

Author Comment

by:Mike Miller
ID: 24367941
Ok yeah that worked. I had it as data.datatable without the namespace and tried that before. Once i added the namespace and just did datatable it worked, thanks guys
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question