sql - SqlDataReader getting rows when no data -


This is incredibly important, I need to present this application in three and a half hours.

Checks the application against the data source to see that whether the value is present in the database and changes in values, depending on whether the value was found in the question or not. The problem is that I have run SQL query with value in question in SSMS and no rows have been returned, and even then, my detitor says that its lines are there.

This means that my application is incorrectly reporting here's my code: new SQL connection ("Data source =. \ SQLEXPRESS; initial catalog = test; integrated security = true;") SqlDataReader = cmd.ExecuteReader if new reader as SQL CMD (SQL, Conn) Conn.Open () dim reader as Reader. HasRows then values ​​= true acctNumber = reader (1) end if reader. Using Close ()

I have deleted the code which is not relevant to this post, but what you want to know is:

Value The Boolean ActNumber String is

Because it is an app for work, I want to include SQL query instead of the problem is the reader if I comment on value = true , correct me Information is received, but leaving it will mean that where the value should be true, it will Addiction also will report.

Thanks in advance!

Edit: Full source code:

  Change the case "business" 'to the local format as it is what is in DB if Microsoft .Visualbestic Lift ( Numberbreak, 2) = "27" then check numbertoc check = numberbreak. (Microsoft Visual Basic.Lift (NumberTok Check, 2), "0") and Sim as String = Sql String = "Select A. Telenumber, C. Account Number" & amp; _ "One from TeleInfo A" & amp; _ "A. CostID for B.Tech.I.I.D. for IN.ER Customer" Join I _ "Inner join accounts si on bPQIID = C. costed" & amp; _ "Where one. Tailnumber = '' & amp; Numberbreak check & amp; New SQL Connection ("Data Source =. \ SQLEXPRESS; Initial Catalog = Test, Continue to Security Information; Truth;" & _ "User ID = Josh; Password = Pozosez;") New SQL Commands as DM CMD Sql, conn) reader as conn.Open () Dim reader SqlDataReader = cmd.ExecuteReader Read if value = true ACctNumber = reader (1) end if reader. Using the Close () on  

comments made before 08/02/10 (mm / day / year):

Value is just a boolean that is returned by the function, indicating that the telephone number ( NumberToCheck ) present in the detected database is present.

Then ...

  Private ACctNumber string as a fixed valve Boolean = False val = checknumber ("3235553469") If the value is then set by 'ACTNumber check mark label 1' must have been done. Text = ActNumber and if  

Well will be returned only if the true number is checked in the Totak test (T example 3235553469) in the database.

After copying the value of the number-point in the SSM and testing the query there, I can verify that the query works as expected.

No, I can not populate datasets due to the amount of information in the table (+/- 9.5m rows). Even with the 'WHERE' filter, the query on resources is very heavy and finally ends in a OutOfMemory exception , so I went with a DataReader.

I am going now to suggest an answer by Darryl as an answer that try the ExecuteScalar option, with the result will be updated.

If your if statement

  If there is a change, then read. Read () then values ​​= true ACctNumber = reader (1) end if  

HasRows displays in some situations, so it is better to avoid it altogether is.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -