MySQL Query with MySQLParameters in C# -
i developing application windows using mysql , c#. have following code:
private void cbocategories_selectedindexchanged(object sender, eventargs e) { databasework dbase = new databasework(); try { dbase.openconnection(); string query = "select * budgetcategory budc_userid=@userid , budc_category=@category"; mysqlcommand cmd = new mysqlcommand("", dbase.conn); cmd.commandtext = query; cmd.parameters.addwithvalue("@userid", userid); cmd.parameters.addwithvalue("@category", cbocategories.selecteditem.tostring()); mysqldatareader reader = cmd.executereader(); while (reader.read()) { setcatid(reader.getstring("budc_category_id")); console.writeline("category id: " + getcatid()); } } catch (mysqlexception ex) { console.writeline("cat error: " + ex.message); } { dbase.closeconnection(); } }
for reason when debug code never goes while loop if nothing ever returned database. know there should in there.
thanks can provide
just trying debug little:
try reducing these 3 lines:
string query = "select * budgetcategory budc_userid=@userid , budc_category=@category"; mysqlcommand cmd = new mysqlcommand("", dbase.conn); cmd.commandtext = query;
to just:
string query = "select * budgetcategory budc_userid=@userid , budc_category=@category"; mysqlcommand cmd = new mysqlcommand(query, dbase.conn);
now put breakpoint on lines add parameters, , make sure userid
, cbocategories.selecteditem.tostring()
have values expect.
also, can confirm no exception thrown?
if not case run query, exact values directly against database , confirm returned.
Comments
Post a Comment