473,405 Members | 2,187 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,405 software developers and data experts.

If loop of datareader

Even though the condition of if loop is true its not going inside if.

Expand|Select|Wrap|Line Numbers
  1. int i=0;
  2. str1="select uname from detail";
  3. SqlCommnad cmd=new SqlCommand(str1,cn);
  4. SqlDataReader rd;
  5. rd=cmd.ExecuteReader();
  6. string hold;
  7. hold=UserName.text;//UserName is name of a text box.
  8. while(rd.Read())
  9. {
  10.     if(hold==rd.GetString(i))
  11.     {
  12.          present=true;//Its not coming inside even when 2 values are same
  13.     }
  14. }
  15.  
Aug 16 '11 #1
3 1614
Dody
11
hi parul,

you may need to trim string variables when you comparing thim

try this
Expand|Select|Wrap|Line Numbers
  1.       if(hold.Trim  == rd.GetString(0).Trim)
  2.          {
  3.          present=true;
  4.          }
  5.  
Aug 16 '11 #2
There were some spaces in case of rd.GetString(i), trim was not working..:(
So i added space in hold and then did the comaprison.
It's working by this way.
Aug 17 '11 #3
Dody
11
good,but the main function of Trim()

is to remove this spaces

sorry i forget to set '()' :( but i expected you get it

try this again :)

Expand|Select|Wrap|Line Numbers
  1.       if(hold.Trim() == rd.GetString(0).Trim())
  2.          {
  3.          present=true;
  4.          }
  5.  
i try this example and work

Expand|Select|Wrap|Line Numbers
  1.  
  2.             string x="asd         ";
  3.             string y="asd ";
  4.             if(x.Trim() ==y.Trim())
  5.             {
  6.                 MessageBox.Show("hiiiiiiiiiii");
  7.             }
  8.  
  9.  
Aug 17 '11 #4

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

Similar topics

2
by: rob | last post by:
I'm having some trouble with this.. My VB datareader seems to skip the first record in the reader. I've looked at my query in enterprise manager to confirm what I am suppose to receive back,...
12
by: Thomas Scheiderich | last post by:
I have 2 dropdowns that are exactly the same and I don't want to re-read for each. Is there a way to do something like below where I read the data, bind to depCity1 and then bind to destCity2. ...
10
by: Scott Richards | last post by:
Hi I am getting a exception while using a datareader here is the code Me.SqlConnection1.Open() Me.SqlReservationCheck.Parameters("@Ref").Value = Ref Dim Reader As SqlClient.SqlDataReader = _...
4
by: Shapper | last post by:
Hello, I have created a datareader function in a asp.net/vb web site. The datareader returns only one record with 2 fields: and In the same aspx.vb I want to use this values as follows:...
1
by: Brent | last post by:
I'm having a hard time wrapping my head around how to build a multi-dimensional array of n length out of a DataReader loop. Take this pseudo-code: ======================================= public...
7
by: Hardik Shah | last post by:
Hi, Generaly to populate combobox , I use following command :- Combobox1.datasource = dataset.tablename combobox1.displaymember = fieldname1 combobox1.valuemember = fieldname2 As I don't...
3
by: Martin Panggabean | last post by:
Hello All, I've kind a logic problem ... I want to fill the listView control in VB.NET with data in my mySql table using Datareader object component. But It seems that the way of how listView...
6
by: dejavue82 | last post by:
This is the result of a JOINed query: question answer 1 a1 1 a2 1 a3 1 a4 2 a1 2 a2
20
by: fniles | last post by:
I am using VB.NET 2003, SQL 2000, and SqlDataReader. As I read data from tblA, I want to populate tblB. I use SQLDataReader for both tables. I do not use thread. When I ExecuteReader on tblB, I...
10
by: jimmy | last post by:
Hi again, sorry for posting two questions so close together but im working on a school project which is due in soon and running into some difficulties implementing the database parts. I have the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.