Click here to Skip to main content
12,352,091 members (32,865 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# SQL convert
i need to convert the sqlDataReader to String for the comparing of database value to user entered text value
how to do?
Posted 6-Jun-12 4:38am
Comments
db7uk 6-Jun-12 10:40am
   
You cant convert an sqlDataReader into a string value? Do you mean you need to get a string value from the database using an sqlDataReader and compare it with a user entered value?
Abhiram KA 7-Jun-12 2:55am
   
same thing check the value from database.
9410662422 26-Apr-13 2:53am
   
@db7uk: I am fetching a column having some string through SqlDataReader and i want to convert it into string i mean like following dummy syntax
rd=cmd.ExecuteReader();
string abc=rd//i mean something should be here to conversion. So have you any idea to do such things.
Abhiram KA 8-Jun-12 8:43am
   
but i converted textbox value into hashMD5 format some secure formate that not equal to get the value like
áÜ9IºY«¾VàWòˆ>
Abhiram KA 8-Jun-12 9:14am
   
deconvertion not done. had a problem
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

As mentioned in the comments by db7uk, you can't convert a datareader into a string. What you CAN do is to use the datareader to pull values.

Here[^] is an article that I found on google that may help you.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

You cannot convert a datareader to a string. But you can do this

while (dr.read())
{
   if (dr["fieldName"].ToString()=="valueToCheck")
   {
       //your logic here
   }
 
}

You can see more of my tutorials here[^]
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

sqlconnection con = new sql connction("connection string");
sqlcommand com = new sqlcommand("select columnname from  tablename",con);
con.open();
sqldatareader dr = com.excutereader();
dr.read();
 
if(!dr.IsDBNull(0) && textbox1.text==dr.GetString(0))
{
    messagebox.show("anything");
}
 
con.close();

hope this helps
  Permalink  
v8
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

this will work in this case

if (dr["City"] != null)
{
objAdsProperties.City = dr["City"] as string;
}
else
{
objAdsProperties.City = "";
}


for integer value

objAdsProperties.BuiltYear = dr["BuiltYear"] as int? ?? default(int);
  Permalink  
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 8 Jun 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100