Solved

Getting more than one data line while using commandtext (Visual Basic.Net)

Posted on 2013-12-13
3
500 Views
Last Modified: 2014-01-13
Good Evening,

I'm trying to work through this application. I'm new to programming and need some help. I'm building a VB.net application that connects to an excel file as a database. When using the attached code... It goes into my database gets some data from one of the sheets/ Rows then shows it in message boxes (I'll do other stuff with it later). That works fine.

My problem is I want it to also grab another row of data from the same sheet and display that data also.

Please help

    Private Sub STapply_Click(sender As Object, e As EventArgs) Handles STapply.Click


        Dim Site = STsiteComboBox.Text
        Dim Team1 = STteam1ComboBox.Text
        Dim Team2 = STteam2ComboBox.Text
        Dim NDS = STndsteamComboBox.Text
        HL_site_View.Text = Site

        Dim Conn As New OleDbConnection
        Dim Comm As New OleDbCommand
        Dim DReader_T1L As OleDbDataReader

        Dim Str As String = ""


        Conn.ConnectionString = CreateConnString("c:\tempTestDB.xls")
        Conn.Open()
        Comm.Connection = Conn
        Comm.CommandText = "SELECT * FROM [TeamsTL$] where Teams= """ & Team1 & """"
        DReader_T1L = Comm.ExecuteReader(CommandBehavior.CloseConnection)


        Try
            While (DReader_T1L.Read)

                MessageBox.Show(DReader_T1L.Item(1))
                MessageBox.Show(DReader_T1L.Item(2))
                MessageBox.Show(DReader_T1L.Item(3))
                MessageBox.Show(DReader_T1L.Item(4))

            End While
        Finally
            DReader_T1L.Close()
        End Try

    End Sub

Open in new window

0
Comment
Question by:AnthonySmithMCP
[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
  • 2
3 Comments
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 39718225
Can you post the execl file and tell us what item you need to get from the sheet as well.
0
 
LVL 1

Author Comment

by:AnthonySmithMCP
ID: 39719178
Attached
tempTestDB.xls
0
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 39719234
Hi AnthonySmithMCP;

This line of code will return all records / Line from the excel work sheet.

Comm.CommandText = "SELECT * FROM [TeamsTL$]

Because you have this line of code in your program

Comm.CommandText = "SELECT * FROM [TeamsTL$] where Teams= """ & Team1 & """"

You are filtering the lines for those lines who's Teams column is empty and who's Team1 column is also empty but Team1 does not exist in the excel sheet so no records will be returned.

To get multiple lines to be returned you need to filter that code line above such that it picks those two lines that you want.
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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

730 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