c# - SQL Table Edit: Add DateTime value in table -


i made sql table editor add info in columns. 1 column set "datetime" in , application can't write . here code:

private void button2_click(object sender, eventargs e)     {   try  {     string connectionstring = @"data source=" + textbox4.text + ";" + "initial catalog=" + textbox1.text + ";" + "user id=" + textbox2.text + ";" + "password=" + textbox3.text;     using (sqlconnection connection = new sqlconnection(connectionstring))     using (sqlcommand command = connection.createcommand())     {         command.commandtext = "insert user_ban (char_id, status, ban_date, ban_hour, ban_end) values (@char_id, @status, datetime @ban_date, @ban_hour, @ban_end)";          command.parameters.addwithvalue("@char_id", "1");         command.parameters.addwithvalue("@status", "1");                   command.parameters.addwithvalue("@ban_date", "1");         command.parameters.addwithvalue("@ban_hour", "1");         command.parameters.addwithvalue("@ban_end", "1");                       connection.open();         command.executenonquery();         messagebox.show("char banned");     } } catch (sqlexception ex) {    messagebox.show(ex.message); } } 

column 'ban_date' set datetime. thank you!

"1" not date. try passing date it

command.parameters.addwithvalue("@ban_date", datetime.today); 

and remove datetime command string

command.commandtext = "insert user_ban                        (char_id, status, ban_date, ban_hour, ban_end)                        values                        (@char_id, @status, @ban_date, @ban_hour, @ban_end)"; 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -