Thread: Time?????

  1. #1
    Registered User planet_abhi's Avatar
    Join Date
    Oct 2002
    Posts
    92

    Time?????

    How do i insert current time in SQL Table???
    What will be the query????
    AbHHinaay

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Quote Originally Posted by planet_abhi
    How do i insert current time in SQL Table???
    What will be the query????
    The SQL and the objects used are for MySQL, but the principal should be the same

    Code:
    string UpdateString = "INSERT INTO SomeTable (DateField) VALUES (?DateField)";
    
    
    MySqlConnection oCon = null;
    MySqlCommand oCom = null;
    try
    {
    	oCon = new MySqlConnection();
    	oCon.ConnectionString = 
    		ConfigurationSettings.AppSettings["ConnectionString"];
    	oCon.Open();
    	oCom = new MySqlCommand();
    	oCom.Connection = oCon;
    				
    	oCom.CommandText = UpdateString;
    						
    	oCom.Parameters.Add("?DateField", DateTime.Parse("01/01/1950"));	
    					
    	oCom.ExecuteNonQuery();
    finally
    {
    	if(oCon != null)
    		oCon.Close();
    }

  3. #3
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    How do i insert current time in SQL Table???
    What will be the query????
    Code:
    INSERT INTO YOUR_TABLE( YOUR_FIELD ) VALUES ( SYSDATE );
    That's Oracle.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  4. #4
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    INSERT INTO myTable ([ADateColumn], [ATextColumn]) VALUES (getdate(), 'Paul Rocks')

    Is the SQL Server query.

    To execute the query, start here:

    http://msdn.microsoft.com/library/de...ClassTopic.asp

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to get current time
    By tsubasa in forum C Programming
    Replies: 3
    Last Post: 05-01-2009, 02:03 AM
  2. Replies: 11
    Last Post: 03-29-2009, 12:27 PM
  3. Help with assignment!
    By RVDFan85 in forum C++ Programming
    Replies: 12
    Last Post: 12-03-2006, 12:46 AM
  4. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 06:00 PM
  5. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM