473,327 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

SQLDataReader.Read() help

I have a function that cals a sql database and spits the rows back to an arraylist for me to do whatever with. I've not had any trouble with it till I ran into this. I pulled some values, copied them to another arraylist and based on the id numbers I run a second query to determine a color change in the html table I'm outputting. My problem is it works perfect when I run in visual studio, however, when I publish it and try it it finds nothing (the read() returns false regardless). I've checked and it is getting the correct sql query passed to it. Any ideas why it might do this?


Thanks
Patrick

Expand|Select|Wrap|Line Numbers
  1.    Shared Sub sqlcmd(ByVal returned As Integer, ByVal query As String, ByVal getdata As Boolean)
  2.         'returned is how many fields are returned
  3.         'query is the sql query to be run
  4.         'getdata is  a switch for whether to load data or not.
  5.         Dim sql As New System.Data.SqlClient.SqlCommand(query, sqlconn)
  6.         sqlconn.Open()
  7.         If getdata Then
  8.             dr = sql.ExecuteReader()
  9.             Dim j = 0
  10.             Dim i
  11.             count = returned
  12.             b.Clear() 'make sure the arraylist is empty
  13.             While dr.Read()
  14.  
  15.                 For i = 0 To returned - 1
  16.                     b.Add(dr(i))
  17.                 Next
  18.                 b.TrimToSize()
  19.  
  20.                 'sets b as an arraylist 
  21.                 'every "returned/count" is a row
  22.                 j = j + 1
  23.             End While
  24.         Else
  25.             sql.ExecuteNonQuery() 'if getdata\=false...Ex: an update query
  26.         End If
  27.         dr.Close()
  28.         sqlconn.Close()
  29.     End Sub
Sep 15 '08 #1
6 2012
Frinavale
9,735 Expert Mod 8TB
Make sure that your database is configured to allow your account to log in remotely...and make sure that your connection string is correct.

-Frinny
Sep 15 '08 #2
balabaster
797 Expert 512MB
Make sure that your database is configured to allow your account to log in remotely...and make sure that your connection string is correct.

-Frinny
Are you using SQL 2005 Express? If so, is IIS and SQL Server running on the same box? The reason I ask is that SQL Server 2005 Express doesn't allow remote connections from different machines on your network, so you will see security issues if the two are on different boxes...
Sep 15 '08 #3
It's talking to a sql 2000 server db that I query several times both automatically and from user interactions. All the other queries are working fine.
Sep 15 '08 #4
Thanks for the help, I stumbled into it, running back thru things again. it was changing the date format on the date variable I was putting in that query.
Sep 15 '08 #5
Frinavale
9,735 Expert Mod 8TB
Thanks for the help, I stumbled into it, running back thru things again. it was changing the date format on the date variable I was putting in that query.
Yeah you really have to watch the Culture settings.
If you are saving dates as an "en-US" culture and the person using the system is running under "fr-FR" then the dates will be formatted incorrectly. Look into using the DateTimeFormatInfo object found in the System.Globalization namespace to help format your dates correctly for storage.

Did you fix the problem?

-Frinny
Sep 15 '08 #6
Yeah you really have to watch the Culture settings.
If you are saving dates as an "en-US" culture and the person using the system is running under "fr-FR" then the dates will be formatted incorrectly. Look into using the DateTimeFormatInfo object found in the System.Globalization namespace to help format your dates correctly for storage.

Did you fix the problem?

-Frinny
Yep, I just wrapped the passed date in a format (string, "MM/dd/yyyy") and it worked perfectly. I'll have to check that DateTime thing, sounds like it could be handy. The added fun is with this database some of the dates are MM/dd/yyyy, some are MM/dd/yy, some are MM/dd/yyyy HH:MM:SS, and some are yyyyddMM. I think the people that originally set it up couldn't make up their minds :)
Sep 16 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Arvind P Rangan | last post by:
Hi All, How do you get all the values of a sqldatareader if it contains multiple resultset. Using sqldatareader.nextresult and sqldatareader.read e.g. While sqldatareader.read ' If not...
8
by: bidllc | last post by:
I have a funtion that works fine and dandy when called from anywhere in my app. It will NOT work when called from inside the class in which it resides. This is the function I'm calling:...
4
by: mimi | last post by:
Hi Please help me out, I can't find a way to close a sqldatareader when error occur at statement cmd.ExecuteReader(). I can't close it in catch because it is local in try scope and I can't...
2
by: Cameron Frasnelly | last post by:
I emulated the code from the .Net Framework help (Titled "Using Stored Procedures with a Command") and I still receive and error... Error Received = "Invalid attempt to read when no data is...
6
by: James P. | last post by:
I'm trying to pass a sqlDataReader from a called function to a calling function but got nothing back and a message saying "An unhandled exception of type 'System.NullReferenceException' occurred in...
7
by: Web learner | last post by:
I am trying to create a method GetDataFor(string column) becaues I have to repeat the same statements for several columns but I get an error as follows: The name 'dr' does not exist in the current...
3
by: Jon Haakon Ariansen | last post by:
Hi, I realize that it's not possible to get the rowcount from SqlDataReader, but if you have a stored procedure where you return @@ROWCOUNT it should be possible to get the rowcount through the...
4
by: nayla | last post by:
I am using 2 SqlDataReader and while(dr.Read()) get only first record and loop stops. its not retriving all of the records but if I comment db1.RunSQLStatement(sql1,out unit_dr); while...
4
by: Cirene | last post by:
I have a sqldatareader that I use to read some data. Later I do a dr.close. In the same sub I later to "dr = MyCommand.ExecuteReader" because I'm trying to reuse the var with a totally different...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.