access two where parameters command in c# -
this how did , data type miss match, tamp integer thinking thing else (i pass integer in tamp @ stage in program). need pass though int? or problem access statement? whole block of code worked without parameter , loop.
the loop me load them in order , important doing
(int = -100; < 100; i++) { try { connection.open(); oledbcommand command = new oledbcommand(); command.connection = connection; string query = "select * table1 status='" + combobox5.text + "'and tamp='" + + "'"; command.commandtext = query; listbox9.items.clear(); oledbdatareader reader = command.executereader(); while (reader.read()) { listbox9.items.add(reader["description"].tostring()); } // messagebox.show("data saved"); connection.close(); } catch (exception ex) { messagebox.show("error " + ex); } }
assuming tamp
defined integer in database, change
"'and tamp='" + + "'";
to
"' , tamp=" + i;
by placing single quotes around in sql command, providing string rather integer database.
if using c# 6 or later, can use string interpolation write string in clearer manner
$"select * table1 status='{combobox5.text}' , tamp={i}"
note not practice security perspective. should never take user input , place directly in sql command, allows users provide malicious input can e.g. delete data or tables. instead, use parameterized queries. comic linked in comments exemplifies this.
Comments
Post a Comment