c# - How to store value from datepicker into string variable -


I have a datepicker textbox I want to store the date which is used in datepicker by using C # in a string variable is selected. What will the code look like?

  String date = DailyPictor Text; // does not work   

I want to store the dates in a database later in the code, such as the following code:

  string sql = "INSERT Tbl_mote (time, date, id) values ​​('"+ + time",' + + + + ", '" +++ "+"); "Npgsql commm command = new NPGSQL commm (Esquilla, Conn. ); Int no = command.ExecuteNonQuery ();   

Date picture:

  & asp: textbox id = "datepicker" runat = "server" & gt; & Lt; / Asp: textbox & gt;   

What happens today's date always saves on the date of variables and not the selected date.

1) Use datepicker.Value to obtain the selected date as the recipient object. At the time of the object there are several functions to create a string for that date.

2) No, I repeat, do not combine strings for SQL parameters. Use the parameters in the query (they start with one for SQL Server) and later add value to the command object. I have not used an NPGSQL command, but SQL server SqlCommand s.

3) You can use (1) to get a string value if you need it, but do not use it to insert it into the database, as long as the objects in the specific database Datetime objects do not understand. Use the date object object that you received instead, as you add it to the command object.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -