c# - What is the format of a date in database ? asp.net -


this code

        establish_connection con = new establish_connection();         string fname    = txtfirstname.text;         string lname    = txtlastname.text;         string email    = txtemailsingup.text;         string password = txtpasswordsignup.text;         string dobday   = ddlday.selectedvalue;         string dobmonth = ddlmonth.selectedvalue;         string dobyear  = ddlyear.selectedvalue;         string dob= dobyear +"/"+ dobmonth +"/"+ dobday;         string gender   = lblgender.selectedvalue;         string username = txtusername.text;           string connstr = configurationmanager.connectionstrings["database"].connectionstring;         sqlconnection conn = new sqlconnection(connstr);              conn.open();          try         {             string constr = "insert users (username,fname,lname,dob,gender,email,password) values (@username,@fname,@lname,@dob,@gender,@email,@password);";             sqlcommand cmd = new sqlcommand(constr,conn);             cmd.parameters.addwithvalue("@password", password);             cmd.parameters.addwithvalue("@username",username);             cmd.parameters.addwithvalue("@dob",dob);             cmd.parameters.addwithvalue("@gender", gender);             cmd.parameters.addwithvalue("@email", email);             cmd.parameters.addwithvalue("@lname", lname);             cmd.parameters.addwithvalue("@fname", fname);               int affectrows = cmd.executenonquery();              response.write("connection established");         }         catch (exception ex)         {             response.write("error" + ex.message.tostring());         }      } 

it keeps telling me errors in dob, , need convert date time type, when convert using convert.todatetime(), still gives me errors. in database type datetime, can me this?

you should doing this:

datetime dob= new datetime(convert.toint32(dobyear), convert.toint32(dobmonth), convert.toint32(dobday)); 

addwithvalue work because value valid datetime.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -