c# - DateTime Oveload -


i trying have output in label example:april 20,2016 4/20/2016:1200:00:am instead

i tried modified can't figure error out

no overload method takes 1 arguments cause code

lbldate.text = rdr.getvalue(4).tostring("mmmm d,yyyy"); 

this entire code.

 private void getdata()     {         sqlconnection con = new sqlconnection("data source = localhost\\sqlexpress;initial catalog = mejonlinemanagementdb00;integrated security=true;");         con.open();         sqlcommand cmd = new sqlcommand(@"select orderprodname,orderprodtype,orderquantity,orderstatus,orderdateordered                                         orders2                                         ordercustomer='"+dropdownlist1.selecteditem.value.tostring()+"'",con);         sqldatareader rdr = cmd.executereader();         if (rdr.hasrows)         {             while (rdr.read())             {                 lblprodname.text = rdr.getvalue(0).tostring();                 lblprodtype.text = rdr.getvalue(1).tostring();                 lblquantity.text = rdr.getvalue(2).tostring();                 lblstatus.text = rdr.getvalue(3).tostring();                 lbldate.text = rdr.getvalue(4).tostring("mmmm d,yyyy");             }         }         con.close();     } 

the problem using object.tostring() method. method, not have arguments. if want convert date, might try this:

datetime dt = datetime.parse(rdr.getvalue(4).tostring()) lbldate.text = dt.tostring("mmmm d,yyyy"); 

edit:

please note, if date column in database contains null-values, parse methode throw exception. testing null mandatory.

string s = convert.tostring(rdr.getvalue(4)); if(!string.isnullorempty(s)) {    datetime dt = datetime.parse(s);    lbldate.text = dt.tostring("mmmm d,yyyy"); } 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -