DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C# (http://www.daniweb.com/forums/forum61.html)
-   -   database problem (http://www.daniweb.com/forums/thread166628.html)

ayi_102 Jan 6th, 2009 11:31 pm
database problem
 
mydb thedb = new mydb();
            MyGlobal oapp = new MyGlobal();

            //define the reader
            System.Data.OleDb.OleDbDataReader theReader = null;

            //defining sql
            string _sql = "SELECT * FROM searchtest WHERE ID = " +  _ddsearch;
            string _sqlupdate = "";

            //execute the reader
            theReader  = thedb.SQLExecute_Reader(_sql);

this code is try to grab the value from _ddsearch variable
if the value is number it works
but if it is string, theReader return null

this is the problem
string _sql = "SELECT * FROM searchtest WHERE ID = " +  _ddsearch;

the code above is for number

how do you make
ID = " +  _ddsearch;
to get variable value as string

I try to put another qutation mark but it is still wrong

Ramy Mahrous Jan 7th, 2009 1:36 am
Re: database problem
 
Is ID a string?

LizR Jan 7th, 2009 3:55 am
Re: database problem
 
it probably needs quote marks round it too or it will try and think its a column name

ayi_102 Jan 7th, 2009 6:21 pm
Re: database problem
 
the problem is that theReader return string and the variable return int(number)
which is i have to format it to string to make the reader read

LizR Jan 7th, 2009 6:35 pm
Re: database problem
 
then do just that :)

Have a guess.


All times are GMT -4. The time now is 7:27 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC