c# insert date time in sql server database




This is A C# Practice code:
      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Data;
      using System.Drawing;
      using System.Linq;
      using System.Text;
      using System.Windows.Forms;
      using System.Data.SqlClient;


      namespace dataentry
      {
          public partial class UserLogin : Form
          {
              public UserLogin()
              {
                  InitializeComponent();
              }
              SqlConnection asdf = new SqlConnection("Data Source=.;Initial Catalog=dataentry;Integrated Security=True;Pooling=False");
         
           private void button1_Click(object sender, EventArgs e)
              {
                  CON.Open();
                  SqlDataAdapter SDA = new SqlDataAdapter("INSERT INTO REGISTER (ID,NAME,GENDER,STATUS,AGE,SALARY,TAX,DOB) VALUES ('" + textBox1.Text + "','" + textBox2.Text + "','" + comboBox1.Text + "','" + comboBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','"+this.dateTimePicker1.Text+"')", CON);
                  SDA.SelectCommand.ExecuteNonQuery();
                  CON.Close();
                  MessageBox.Show("SAVED SUCCEESSFULLY !!!!!");
                  button4_Click(sender, e);
              }
            
          }
      }

Video For Result:



Share on Google Plus

About Unknown

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Facebook Comment