c# - Database query ignores the first row from the table -
i'm having problem getting result of first row table. ignores , results second row instead.
the query needs result highest or equal value column_b value given in textbox1.
i.e if enter 12 textbox1, result should be: column_a = 1,5 | column_b = 18,5 ignores first row , gives result of column_a = 2,5 | column_b = 25
example of table being used:
+----------+----------+ | column_a | column_b | +----------+----------+ | 1,5 | 18,5 | | 2,5 | 25 | | 4 | 34 | | 6 | 47 | +----------+----------+
the code:
//table used database string tableused = "main_table"; //connecting database oledbconnection connection = new oledbconnection("provider=microsoft.jet.oledb.4.0;data source=data\\db\\database.mdb"); connection.open(); //database query oledbcommand select = new oledbcommand(); select.connection = connection; select.commandtext = "select top 1 column_a,column_b " + tableused + " column_b+0 >=" + textbox1.text + "+0 order column_b+0 asc"; //reading query output oledbdatareader reader = select.executereader(); while (reader.read()) { label5.text = (reader[0].tostring()); label6.text = (reader[1].tostring()); } reader.close(); connection.close();
anyone have solution problem?
you using text data type numeric values.
what's happening +0
code querying values of 18.50
, 250
etc. , 250
larger or equals input +0
, e.g. 120
. 18.50
smaller, not returned in result set.
microsoft access lot of implicit conversion, yes, cannot trust doing.
if want numeric values, use numeric data types.
Comments
Post a Comment