?
Solved

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

Posted on 2013-12-13
3
Medium Priority
?
502 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 2000 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

How To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

777 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