| | |
check if datatable is empty
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
What is the error you are getting?
You could do a test for the number of records and only loop if it is greater than 0.
And how are you looping through the table?
Pseudo-Code:
Hope this helps
You could do a test for the number of records and only loop if it is greater than 0.
And how are you looping through the table?
Pseudo-Code:
VB.NET Syntax (Toggle Plain Text)
Dim dr As OleDbDataReader = cmd.ExecuteReader() Do While dr.Read ... ... Loop
Hope this helps
•
•
Join Date: May 2005
Posts: 12
Reputation:
Solved Threads: 0
Dim myConnStr As String = "Provider=Microsoft.jet.OLEDB.4.0;Data Source=" + myPath
Dim myConn As New OleDb.OleDbConnection(myConnStr)
Dim myAdapt As New OleDb.OleDbDataAdapter(myQuery, myConn)
Try
myConn.Open()
Dim myReader As New DataSet
myAdapt.Fill(myReader)
**
** I need to check if myReader is empty
**
tbGATE.Text = myReader.Rows(0)("dGate")
tbCONC.Text = myReader.Rows(0)("dConc")
tbPAY.Text = myReader.Rows(0)("dPayment")
**
** I need to check if myReader.Rows(0)("dWeather") is empty
**
cbWEATHER.DisplayMember = myReader.Rows(0)("dWeather")
myConn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Dim myConn As New OleDb.OleDbConnection(myConnStr)
Dim myAdapt As New OleDb.OleDbDataAdapter(myQuery, myConn)
Try
myConn.Open()
Dim myReader As New DataSet
myAdapt.Fill(myReader)
**
** I need to check if myReader is empty
**
tbGATE.Text = myReader.Rows(0)("dGate")
tbCONC.Text = myReader.Rows(0)("dConc")
tbPAY.Text = myReader.Rows(0)("dPayment")
**
** I need to check if myReader.Rows(0)("dWeather") is empty
**
cbWEATHER.DisplayMember = myReader.Rows(0)("dWeather")
myConn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
(For sake of confusion, I would not name my Dataset as myReader - seems to refer to a datareader to someone not knowing what you are coding for.... just some programming edicate I thought I should pass on)
Saying that......
Add the line
If myReader.Tables("dWeather").Rows.Count > 0 Then
Hope this helps
Saying that......
Add the line
If myReader.Tables("dWeather").Rows.Count > 0 Then
Hope this helps
•
•
•
•
Originally Posted by Robert Walker
Dim myConnStr As String = "Provider=Microsoft.jet.OLEDB.4.0;Data Source=" + myPath
Dim myConn As New OleDb.OleDbConnection(myConnStr)
Dim myAdapt As New OleDb.OleDbDataAdapter(myQuery, myConn)
Try
myConn.Open()
Dim myReader As New DataSet
myAdapt.Fill(myReader)
**
** I need to check if myReader is empty
**
tbGATE.Text = myReader.Rows(0)("dGate")
tbCONC.Text = myReader.Rows(0)("dConc")
tbPAY.Text = myReader.Rows(0)("dPayment")
**
** I need to check if myReader.Rows(0)("dWeather") is empty
**
cbWEATHER.DisplayMember = myReader.Rows(0)("dWeather")
myConn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
•
•
Join Date: Nov 2009
Posts: 15
Reputation:
Solved Threads: 0
0
#10 17 Days Ago
You probably can guess this from the previous threads but I use:
VB.NET Syntax (Toggle Plain Text)
dim MyTable as Datatable 'fill datatable.... If (MyTable Is Nothing) Or (MyTable.Rows.Count =0 ) Then 'it's empty Else 'it exists and there are rows End if
Last edited by niek_e; 15 Days Ago at 10:23 am. Reason: Added code-tags
![]() |
Similar Threads
- null check of resultset (JSP)
- If stdin is empty? (Python)
- usinfg c++, how would you check if a cd-rw is blank... (C++)
- "Save Target As.." isn't working in IE6 (Web Browsers)
Other Threads in the VB.NET Forum
- Previous Thread: Print a table
- Next Thread: Get Date from Database Access
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
.net .net2008 2005 2008 access account application array arrays basic bing button buttons c# center check checkbox code convert crystalreport data database datagrid datagridview date dissertation dissertations dropdownlist excel fade file-dialog filter ftp generatetags google gridview hardcopy images inline input insert intel internet listview mobile monitor ms net networking objects output panel passingparameters picturebox picturebox1 port position print printing problem project read remove save searchbox searchvb.net select serial server shutdown soap sorting survey table tcp temperature text textbox timer timespan toolbox trim update user validation vb vb.net vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio2008 web webbrowser winforms wpf year






