 |
| ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.1 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
|
|
|
|

August 23rd, 2004, 07:19 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2004
Posts: 245
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
SqlDataReader question with SQL
Hello
I have question about SqlDataReader.
In my sql table when ResetNo is INT then this code doesn't work, even when I first get the value as integer then change to string. But this works fine when I set in sql table ResetNo as nvarchar, and of course I just get it as string and I don't need to change from integer to string.
Why does this not work when I have ResetNo as INT?????
I really want to keep ResetNo as INT and not Nvarchar.
This is the code when I keep ResetNo as INT and not nvarchar.
Why doesn't it work???
Thank you.
Public Shared Function GetResetNo(ByVal sEmail As String) As String
Dim myConn As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("C onnectionString"))
Dim sSql As String = "SELECT ResetNo FROM OCVBUG_Member WHERE Email = @Email"
Dim selectCmd As New SqlCommand(sSql, myConn)
selectCmd.CommandType = CommandType.Text
selectCmd.Connection = myConn
selectCmd.Parameters.Add("@Email", SqlDbType.NVarChar, 100)
selectCmd.Parameters("@Email").Value = Replace(sEmail, "'", "''")
Dim iResetNo As Integer
Dim sResetNo As String
Try
Dim da As SqlDataReader
myConn.Open()
da = selectCmd.ExecuteReader(CommandBehavior.SingleRow)
da.Read()
iResetNo = da.Item("ResetNo")
sResetNo = Cstr(iResetNo)
myConn.Close()
Catch ex As Exception
sResetNo = "Error"
Finally
If myConn.State = ConnectionState.Open Then
myConn.Close()
End If
End Try
Return sResetNo
End Function
|
|

August 23rd, 2004, 07:52 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Hey,
Try:
da.GetInt32("ResetNo")
Brian
|
|

August 25th, 2004, 07:42 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2004
Posts: 245
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hello bmains,
iResetNo = da.GetInt32("ResetNo")
doens't work
What can be the problem?????
|
|

August 25th, 2004, 10:21 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Hey,
Well then, what is the actual error that you are getting? From what I see, everything is fine. Also let me know what line of code the error is from.
Brian
|
|

August 25th, 2004, 12:37 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
You probably need a 'do while' loop in front of the da.Read()
|
|

August 25th, 2004, 04:36 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2004
Posts: 245
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Try
Dim da As SqlDataReader
myConn.Open()
da = selectCmd.ExecuteReader(CommandBehavior.SingleRow)
da.Read()
iResetNo = da.GetInt32("ResetNo")
sResetNo = CStr(iResetNo)
myConn.Close()
Catch ex As Exception
sResetNo = "Error"
Finally
If myConn.State = ConnectionState.Open Then
myConn.Close()
End If
End Try
response.write("sResetNo")
---------------------------------------------------------------------
stu9820
Are you sure I need to do a do while loop in front of the da.Read()
because I am only getting one row: da = selectCmd.ExecuteReader(CommandBehavior.SingleRow) .
When I run this the exception gets thrown.
|
|

August 26th, 2004, 07:35 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Hey,
You probably don't need to loop through. Also, change response.write("sResetNo") to Response.Write(sResetNo) to find the response. Are you getting the text Error, or are you actually getting an exception? If you are getting an exception, it's because o something outside the try catch block.
Brian
|
|
 |