mysql - sql does not work for specific query c# -
i have query:
datatable ordersbetween = dm.getdatatablebyquery("select * [reservering]"); // 'where datumstart between " + @row["datumstart"] + " , " + @row["datumeind"] + ""); int totalorders = 0; foreach (datarow orders in ordersbetween.rows) { totalorders = totalorders + 1; } if (totalorders > 0) { %> orders found <% } and somehow totalorders remains 0 though have 8 entries in reservering.
but query practicly same works fine.
datatable tafellijst = dm.getdatatablebyquery("select * [tafel]"); foreach (datarow tafelrow in tafellijst.rows) { %> <option value="<%=tafelrow["id"]%>">nummer - <%=tafelrow["id"]%> | plaatsen - <%=tafelrow["plaatsen"]%></option> <% } %> you can see ive simeplyfied first query, real query needs select entries between specific datetime's every datetime.tryparse() results in datetime minimum value not actual datetime.
ive added getdatatablebyquery method here:
public datatable getdatatablebyquery(string query) { sqlconnection con = new sqlconnection(); string connectionstring = system.configuration.configurationmanager.connectionstrings["connectionstring"].connectionstring; con.connectionstring = connectionstring; seek { con.open(); sqldataadapter da = new sqldataadapter(query, con); datatable dt = new datatable(); da.fill(dt); con.close(); homecoming dt; } grab (nullreferenceexception) { datatable empty = new datatable(); homecoming empty; } grab (sqlexception) { datatable empty = new datatable(); homecoming empty; } } ive added web.config here:
<configuration> <system.web> <compilation debug="true" targetframework="4.0" /> </system.web> <connectionstrings> <add name="connectionstring" connectionstring="data source=.\sqlexpress;attachdbfilename=|datadirectory|\picobellodatabase.mdf;integrated security=true;user instance=true" providername="system.data.sqlclient"/> </connectionstrings> </configuration> this question answered. utilize datatable.rows.count , check info echod. echod info between html element became invisible!
thanks help!
you alter code to
if (ordersbetween.rows.any()) { %> orders found <% } although foreach should emumerate rows surprising getting 0. how confident getdatatablebyquery() doing ought to?
c# mysql datetime
No comments:
Post a Comment