How do I pull data from an excel sheet that only matches certain criteria and display in a label or

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<div id="x_highlighter_82235


Forgive the noob.<br/>
<br/>
Excel 2010 + VB.net 2010 express<br/>
<br/>
I have a vb.net <br/>
project that connects to an excel workbook (oledb) and fills it with user <br/>
entered data on a daily basis.<br/>
<br/>
It works great!<br/>
<br/>
The excel sheet has <br/>
15 Columns and the data expands downward as users input data every day. Each row <br/>
is a different record.<br/>
<br/>
One of my columns, (N) is one titled <br/>
"CallbackRequired" which will only have "Yes" or "No" and another column (O) is <br/>
"WhenCall" which saves the date the customer is to be called back on.<br/>
<br/>
In <br/>
my vb.net application, I would like to put either a label or a textbox on a form <br/>
that will display at runtime all the records in that sheet under the column <br/>
"CallbackRequired" that have a "Yes" that match only the current date in the <br/>
"WhenCall" column.<br/>
<br/>
I would like to display the entire row of 15 columns <br/>
(the record) that match the critera I just described on a number delimited list, <br/>
1 per row when the program is run.<br/>
<br/>
I figure this is most likely done with <br/>
a SQL statement or a DataGrid. Either way I know not how to do it. I am sure <br/>
that I could muddle through the statement itself, <I know the general syntax <br/>
of an SQL Statement> but I am not sure, (even if I had the correct syntax), <br/>
how to display or return the data I am requesting.<br/>
Although I dont think you <br/>
need to see the code to help me with this question I have included it anyway for <br/>
reference.<br/>
Any help is greatly appreciated.





<pre class="prettyprint lang-vb Try
olecon = New OleDb.OleDbConnection
olecon.ConnectionString = connstring
olecomm = New OleDb.OleDbCommand
olecomm.CommandText = _
"Select TodaysDate, CustomersName, CustomersPhoneNumber, Last4ofSS, Billing, UpgradeAvailable, HowMany, HPC, MBB, GWG, SellDevice, HowManyTwo, Comments, CallbackRequired, WhenCall from [Traffic Monitor$]"
olecomm.Connection = olecon
olecomm1 = New OleDb.OleDbCommand
olecomm1.CommandText = "Insert into [Traffic Monitor$] " & _
"(TodaysDate, CustomersName, CustomersPhoneNumber, Last4ofSS, Billing, UpgradeAvailable, HowMany, HPC, MBB, GWG, SellDevice, HowManyTwo, Comments, CallbackRequired, WhenCall) values " & _
"(@tDate, @tName, @tNumb, @tLast, @tBill, @tUp, @tHow, @tHPC, @tMBB, @tGWG, @tDevice, @tHowTwo, @tComm, @tCall, @tWhen)"
olecomm1.Connection = olecon
pram = olecomm1.Parameters.Add("@tDate", OleDb.OleDbType.VarChar)
pram.SourceColumn = "TodaysDate"
pram = olecomm1.Parameters.Add("@tName", OleDb.OleDbType.VarChar)
pram.SourceColumn = "CustomersName"
pram = olecomm1.Parameters.Add("@tNumb", OleDb.OleDbType.VarChar)
pram.SourceColumn = "CustomersPhoneNumber"
pram = olecomm1.Parameters.Add("@tLast", OleDb.OleDbType.VarChar)
pram.SourceColumn = "Last4ofSS"
pram = olecomm1.Parameters.Add("@tBill", OleDb.OleDbType.VarChar)
pram.SourceColumn = "Billing"
pram = olecomm1.Parameters.Add("@tUp", OleDb.OleDbType.VarChar)
pram.SourceColumn = "UpgradeAvailable"
pram = olecomm1.Parameters.Add("@tHow", OleDb.OleDbType.VarChar)
pram.SourceColumn = "HowMany"
pram = olecomm1.Parameters.Add("@tHPC", OleDb.OleDbType.VarChar)
pram.SourceColumn = "HPC"
pram = olecomm1.Parameters.Add("@tMBB", OleDb.OleDbType.VarChar)
pram.SourceColumn = "MBB"
pram = olecomm1.Parameters.Add("@tGWG", OleDb.OleDbType.VarChar)
pram.SourceColumn = "GWG"
pram = olecomm1.Parameters.Add("@tDevice", OleDb.OleDbType.VarChar)
pram.SourceColumn = "SellDevice"
pram = olecomm1.Parameters.Add("@tHowTwo", OleDb.OleDbType.VarChar)
pram.SourceColumn = "HowManyTwo"
pram = olecomm1.Parameters.Add("@tComm", OleDb.OleDbType.VarChar)
pram.SourceColumn = "Comments"
pram = olecomm1.Parameters.Add("@tCall", OleDb.OleDbType.VarChar)
pram.SourceColumn = "CallbackRequired"
pram = olecomm1.Parameters.Add("@tWhen", OleDb.OleDbType.VarChar)
pram.SourceColumn = "WhenCall"
oleadpt = New OleDb.OleDbDataAdapter(olecomm)
ds = New DataSet
olecon.Open()
oleadpt.Fill(ds, "Traffic Monitor")


Then I fill the data from the form....

After I get the data from the form....

ds.Tables(0).Rows.Add(dr)
oleadpt = New OleDb.OleDbDataAdapter
oleadpt.InsertCommand = olecomm1
Dim i As Integer = oleadpt.Update(ds, "Traffic Monitor")

Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
olecon.Close()
olecon = Nothing

olecomm = Nothing
oleadpt = Nothing
ds = Nothing
dr = Nothing
pram = Nothing
End Try
Then I init everything to clear the form.
[/code]
<br/>











































View the full article
 
Back
Top