Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics 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
 
Old December 29th, 2004, 03:27 PM
Registered User
 
Join Date: Dec 2004
Location: Amsterdam, , Netherlands.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Ridouan
Default Reading Data From SQL

Hi Guys,

I am wondering if somone could help me with this?
I have a problem reading some data from an SQL Database.

I need Date.Today and some other text from the Database because. I am making a digital Agenda that shows todays tasks.

Code:
Dim myDataReader As SqlDataReader
Dim mySqlConnection As SqlConnection
Dim mySqlCommand As SqlCommand

mySqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("C onnectionString"))
mySqlCommand = New SqlCommand("Select ItemID, TimeStamp, TimeText, Heading From Items WHERE DateStamp='" & Date.Today & "' AND OwnerKey='" & Request.Cookies("KappersUnlimited_Username").Value & "' ORDER BY TimeText", mySqlConnection)

mySqlConnection.Open()
myDataReader = mySqlCommand.ExecuteReader(CommandBehavior.CloseCo nnection)

Do While (myDataReader.Read())

            If myDataReader.Item("TimeStamp") = "9" Then
                TestLink9.Text = myDataReader.Item("TimeText") & " " & "-" & " " & myDataReader.Item("Heading")
            End If

            If (myDataReader.IsDBNull(0)) Then
                TestLink9.Text = ""
            Else
                TestLink9.Text = "No Item found"

            End If
            '---------------------------------------------------------
If myDataReader.Item("TimeStamp") = "10" Then
                TestLink9.Text = myDataReader.Item("TimeText") & " " & "-" & " " & myDataReader.Item("Heading")
            End If

            If (myDataReader.IsDBNull(0)) Then
                TestLink10.Text = ""
            Else
                TestLink10.Text = myDataReader.Item("TimeStamp")
            End If
            '------------------------------------------------------
etc.....

The Problem discription:
When i have no records i receive the following error:
Invalid to read when no data is present.(Tried too reslove this but no success).

Second(When all records are present):
It seems that the SqlDataReader is not attempting to read all data.

I tried Datasets, SqlDataAdaptersand Tables.
This is an ASP.NET website using SQL Server and to bin data i am now using Linkbuttons.

Thanks for your help.


 
Old January 7th, 2005, 06:01 AM
Registered User
 
Join Date: Dec 2004
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

You say you don't get all data when all records are present.

I didn't think you could construct the Select string, the way you do in ASP.NET and get it to work.

I would use parameters like this

dim objparameter as sqlclient.sqlparameter
("@datetoday",sqldbtype.datetime)
objparameter.direction = parameterdirection.input
objparameter.value = Date.today
mysqlcommand.parameters.add(objparameter)

dim objparameter1 as sqlclient.sqlparameter
("@Username",sqldbtype.varchar,30)
objparameter.direction = parameterdirection.input
objparameter.value = Request.Cookies("KappersUnlimited_Username")
mysqlcommand.parameters.add(objparameter1)

The WHERE-clause

"WHERE DateStamp= @datetoday AND OwnerKey = @Username ORDER BY TimeText"

I hope this helps a little

Regards
Finn



 
Old January 31st, 2005, 05:43 PM
Registered User
 
Join Date: Dec 2004
Location: Amsterdam, , Netherlands.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Ridouan
Default

Thanks Finn.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Error reading data from excel to sql using ASP m_soni21 Classic ASP Professional 1 June 17th, 2008 12:40 AM
Reading data from ms sql RAGHAVENDRAN C# 3 November 26th, 2007 05:26 AM
reading data darkhalf XSLT 1 September 7th, 2006 02:51 PM
Reading Multipart form data dotnetprogrammer VS.NET 2002/2003 0 July 12th, 2005 05:31 AM
Reading data from database... Thomas82 Classic ASP Databases 3 February 25th, 2004 03:58 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.