Hello everyone. I'm beginner and i trying to make time register system. But i can't insert my datetime to my database.Here's the code that i wrote

private void button1_Click(object sender, EventArgs e)
        {
            string dt;   
            string dt2;
            DateTime date = DateTime.Now;    
            DateTime date2 = DateTime.Now;    
            dt = date.ToLongTimeString();        // display format:  11:45:44 AM
            dt2 = date2.ToShortDateString();         // display format:  5/22/2010

            SqlConnection conn = new SqlConnection("data source=dulguun-pc\\sqlexpress; database=tsag_burtgel; Integrated security=true");
            conn.Open();

            SqlCommand cmd = new SqlCommand();

            if (comboBox1.SelectedItem ==null)
            {
                MessageBox.Show("Та дансны кодоо оруулна уу");
            }
            else
            {
                int code = Convert.ToInt32(comboBox1.SelectedItem);
                cmd.Parameters.Add("@dugaar", SqlDbType.Int).Value = code;  
            }            

            if (radioButton1.Checked == true)
            {
                cmd.Parameters.Add("@time_in", SqlDbType.NVarChar,50).Value = dt;
                cmd.Parameters.Add("@date_in", SqlDbType.NVarChar, 50).Value = dt2;
            }
            else
            {
                cmd.Parameters.Add("@time_in", SqlDbType.NVarChar, 50).Value = dt;
                cmd.Parameters.Add("@date_in", SqlDbType.NVarChar, 50).Value = dt2;
            }
            if (radioButton2.Checked == true)
            {
                cmd.Parameters.Add("@time_out", SqlDbType.NVarChar, 50).Value = dt;
                cmd.Parameters.Add("@date_out", SqlDbType.NVarChar, 50).Value = dt2;
            }
            else
            {
                cmd.Parameters.Add("@time_out", SqlDbType.NVarChar,50).Value = dt;
                cmd.Parameters.Add("@date_out", SqlDbType.NVarChar, 50).Value = dt2;
            }

            cmd.CommandText = "Insert into ajilchin values(@dugaar,@date_in,@date_out,@time_in,@time_out)";
            cmd.Connection = conn;
            cmd.ExecuteNonQuery();

            load();

            conn.Close();
            comboBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";

please tell me what should i do and what i did wrong

duuguu welcome to the forums, please take some time and introduce your self in http://www.daniweb.com/forums/forum165.html

Please familiarise yourself with rules. Don't hijack threads.

P.S. use code tagging.

commented: Words. +9

Post Deleted

try this

DateTime.Now.ToString("yyyyMMdd hh:mm:ss:fff");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.