Solved

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

Posted on 2013-12-13
3
494 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
  • 2
3 Comments
 
LVL 62

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 62

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now