Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i need to convert the sqlDataReader to String for the comparing of database value to user entered text value
how to do?
Posted
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?
Abhi KA 7-Jun-12 2:55am    
same thing check the value from database.
Ashish Jain(Be Jovial) 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.
[no name] 8-Jun-12 8:40am    
please post your code.... that you want
Abhi 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òˆ>

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);
 
Share this answer
 
v3
C#
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
 
Share this answer
 
v8
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900