 |
| General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category.
** PLEASE BE SPECIFIC WITH YOUR QUESTION **
When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

April 27th, 2005, 09:31 PM
|
|
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
objReader problem
Hi,
im actually have both frame working with my notebook, my webmatrix is targeting to .net Framework 1.1, even my vb compiler,
Here my vb compiler path:
C:\WINNT\Microsoft.NET\Framework\v1.1.4322\vbc.exe
When i compiling my code behind, it show me
HasRows is not a member of System.Data.SqlClient.SqlDataReader
Once i changed objReader.HasRows to ObjReader.Read=True, no more error. below is my event code.
Sub CheckPartCavity()
StrSql="Select CavityAl from tbl_PartCav Where PartNum like @PartNum"
ObjCmd=New SqlCommand(StrSql, ObjConn)
With ObjCmd.Parameters:
.Add(New SqlParameter("@PartNum", "%" & tbPartNum.Text & "%"))
End With
ObjCmd.Connection.Open()
ObjReader=ObjCmd.ExecuteReader()
if objReader.HasRows
'if ObjReader.Read=True
DdlCavityAl.DataSource=ObjReader
DdlCavityAl.DataBind()
DdlCavityAl.Visible=True
Else
DdlCavityAl.Visible=False
End if
ObjClose()
End Sub
Any idea wat happened? I need to use objReader.HasRows properties, because objReader.Read=True never return the 1st record in my table...
Cheers
life's Ng
|
|

April 28th, 2005, 09:23 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Can you verify that the query you are calling is actually returning data?
|
|

April 28th, 2005, 07:48 PM
|
|
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Yes, it returning data, but with using ObjReader.Read=True , it always start returning with the 2nd data. Let say the query gets Data "A", "B", "C" with using ObjReader.HasRows, once i change it to objReader.Read=True, the dropdownlist will only display "B", "C", it missed out the "A".
wat i know is the reader.HasRows property invented during .net framework 1.1 , Reader.Read is an old version of .net framework 1.0...
Pls feel free if im not making tis clear, any idea wat happened here?
Hope to hear from u soon.
Regards
life's Ng
|
|

April 28th, 2005, 09:30 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
.Read() reads the next row in the result set, so you'll always get n-1 rows in the object you are binding to. So you are correct with using .HasRows, but I can't imagine why that isn't working for you.
http://msdn.microsoft.com/library/de...srowstopic.asp
You left out the " Then" for the if statement, but I imagine you already found that error.
- Peter
|
|

April 29th, 2005, 02:06 AM
|
|
Friend of Wrox
|
|
Join Date: Apr 2005
Posts: 186
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
I did not see the Declaration of you objDatareader.
If it of type System.Data.IDataReader you will not be able to call HasRows propetry because it dosn't have.
But If you are using System.Data.SqlClient.DataReader, you will be able to call HasRows.
I think this is the issue,bcoz usually webmatrix uses System.Data.IDataReader in the code generated by wizards.
Prashant
|
|

May 3rd, 2005, 05:00 AM
|
|
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Peter & Prashant!
Thanks for ur reply!
Mr. Peter, Thansk for ur infor.
May i know whats the difference btw
<b> if objReader.HasRows</b>
<b> if objReader.HasRows Then </b>
I read tis somehow but forgot alrd... it'll be the best if u can show some codes for the different btw them. i cant tell the difference actually...
Mr. Prashant, i did Declare my objDataReader and im using System.Data.SqlClient.DataReader. Im able to call HasRows from my code behind, it just show me the error when i tried to compile it... am i missed out something else...?
Best Regards
life's Ng
|
|

May 3rd, 2005, 07:24 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
You shouldn't be able to compile "If ... " without the "Then". That's part of the VB.NET syntax. You simply have to use "If ... Then".
- Peter
|
|

May 3rd, 2005, 09:18 AM
|
|
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
This is weird too... im able to compile "if..." without the "Then".... sometimes i use "Then", and sometimes i dont feel like using it, but it is all working.
But for the HasRows case, whether i use it or not, i still getting the error...
in future, i'll use "Then" all the way, Thanks Peter!
Best Regards
life's Ng
|
|

May 3rd, 2005, 11:36 AM
|
|
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
i cant figure any things wrong here... my vb compiler version is 7.10.6001.4, do i need to update it..?
Regards
life's Ng
|
|

May 3rd, 2005, 06:45 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
That's the version that ships with .NET 1.1.
- Peter
|
|
 |