c# - Call DateTime argument from Class -
i need call query between dates
class membersched { static datatable getmemberrecords(datetime date, datetime date2) { var connsettings = configurationmanager.connectionstrings["mydb"]; { string cn = connsettings.connectionstring; mysqlconnection conn = new mysqlconnection(cn); mysqlcommand cmd = new mysqlcommand("select value 1, value 2, value 3, value 4 sometable datefrom >= cast(@startdate date) , dateto <= cast(@enddate date)", conn); cmd.parameters.addwithvalue("@startdate", date); cmd.parameters.addwithvalue("@enddate", date2); mysqldataadapter data = new mysqldataadapter(cmd); conn.open(); datatable dt = new datatable(); data.fill(dt); return dt; } } } public object querybetweendate() { datatable table = getmemberrecords(); return table; } private void datepicker_valuechanged(object sender, eventargs e) { //i don't know should put in here } private void datepicker2_valuechanged(object sender, eventargs e) { //i don't know should put in here }
i'm stumped on this, i'm still new in c#, query works fine have tried in mysql beforehand, date arguments on getmemberrecords dont know if right , im getting error on public object querybetweendate()
your sql close, not quite. try this:
select value 1, value 2, value 3, value 4 sometable datefrom between @startdate , @enddate
you shouldn't have cast datetime variables since connector automatically long pass in datetime objects parameters. between sql operator takes care of making sure between right dates.
other casts, there wasn't technically wrong original sql, between little easier understand.
Comments
Post a Comment