Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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.


Reply With Quote
  #2 (permalink)  
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



Reply With Quote
  #3 (permalink)  
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.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:26 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.