Solved

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

Posted on 2013-12-13
3
501 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

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

691 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