How to check if SqlDataAdapter is empty?

1,362 views
Skip to first unread message

Learner

unread,
Aug 8, 2005, 12:20:25 PM8/8/05
to VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hi friends,
How do i check if
Dim adapter As SqlClient.SqlDataAdapter = New
SqlClient.SqlDataAdapter(CType(cmd, SqlClient.SqlCommand))

is empty?

I have a sql that returns some results when made a search with a last
name and first name then i data bind the results to a grid. Now i have
a situation to handle in case if doesn't return any results. I am not
using the stored proc just the sql that builds dynamically based on how
many fields were entered by the user.

so i am just wondering is there any way to check 'adapter' in the line
of code is empty? that means if the query doesn't return any results(0
rows).

Thanks
-L

swayze

unread,
Aug 9, 2005, 8:14:34 AM8/9/05
to VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
if ds.Tables[0].Rows.Count == 0; //no returned rows

Markis Taylor

unread,
Aug 9, 2005, 8:36:20 AM8/9/05
to DotNetDe...@googlegroups.com
Instead of using an SqlDataAdapter can you use an SqlDataReader?

The SqlDataReader class has the HasRows member.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatasqlclientsqldatareadermemberstopic.asp

Stephen Russell

unread,
Aug 9, 2005, 9:58:22 AM8/9/05
to DotNetDe...@googlegroups.com
swayze <mailto:marco....@gmail.com> wrote this on Tuesday, August 09,
2005 7:15 AM:

> if ds.Tables[0].Rows.Count == 0; //no returned rows

That's after a bind to a ds. I was curious if you could determine before
your binding the data???

Stephen Russell
S.R. & Associates
Memphis, TN 38115

901.246-0159

http://spaces.msn.com/members/srussell/

Reply all
Reply to author
Forward
0 new messages