Click here to Skip to main content
15,881,027 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#


<br />
dateTimePicker1.Format = DateTimePickerFormat.Custom;<br />
            dateTimePicker1.CustomFormat = "dd/MM/yyyy";<br />
            dateTimePicker2.Format = DateTimePickerFormat.Custom;<br />
            dateTimePicker2.CustomFormat = "dd/MM/yyyy"; <br />
<br />
            DateTime date = dateTimePicker1.Value;<br />
            this.Text = date.ToString();<br />
            DateTime date1 = dateTimePicker2.Value;<br />
            this.Text = date1.ToString();<br />
<br />
<br />
<br />
            SqlConnection myConnection = new SqlConnection("Server=(local);Database=ERP2014-2015;Trusted_Connection=True;");<br />
            myConnection.Open();<br />
<br />
<br />
<br />
            using (SqlConnection connection = new SqlConnection(connectionString))<br />
            {<br />
<br />
                SqlCommand myCommand = new SqlCommand();<br />
                myCommand.CommandText = "INSERT INTO dbo.ComapnyName([CompanyName], [GovermentID], [RegistrationNumber], Address1, Address2, PostalCode, City, FromDate, ToDate) VALUES ('" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox8.Text + "','" + textBox7.Text + "," + date.ToString() + "," + date1.ToString() + "')";<br />
<br />
<br />
<br />
Posted
Comments
Avik Ghosh22 11-Feb-15 1:19am    
Please pass parameters in query.
Please read :
http://www.w3schools.com/sql/sql_injection.asp
[no name] 11-Feb-15 1:25am    
just know how to save date picker value in database in C# windows application?
Avik Ghosh22 11-Feb-15 1:57am    
http://www.c-sharpcorner.com/uploadfile/mahesh/C-Sharp-datetimepicker-control/

it is depend on database field. if you take data type string then then DateTimePicker.Text.ToString() are used and if datatype is date then u can save DateTimePicker.Text or DateTimePicker.Value
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900