XPO Learning 1 (getting database server time)

Source: Internet
Author: User
Tags oracleconnection
When learning XPO, you need to connect to the database and obtain the database server time to connect ORACLESession. DefaultSession. ConnectionnewOracleConnection (DataSourcedbserver; UserIDsystem; Passwordoracle); Session. defacedsession. AutoCreateOptionAutoCreateOpti

When learning XPO, you need to connect to the database and obtain the database server time to connect to the ORACLE Session. defaultSession. connection = new OracleConnection (Data Source = dbserver; User ID = system; Password = oracle); Session. defaultSession. autoCreateOption = AutoCreateOpti

When you start to learn XPO, you need to connect to the database and obtain the database server time to connect to ORACLE

Session. DefaultSession. Connection = new OracleConnection ("Data Source = dbserver; User ID = system; Password = oracle ");
Session. DefaultSession. AutoCreateOption = AutoCreateOption. SchemaOnly;
Session. DefaultSession. Connect ();

Read server time:

Public static class oracleGetsysDate {
Public static DateTime sysDate ()
{
System. Data. IDbCommand command;
// System. Data. IDataReader reader;
Command = DevExpress. Xpo. Session. DefaultSession. Connection. CreateCommand ();

Command. CommandText = "Select sysdate from dual ";
// Reader = command. ExecuteReader ();
String dtm = command. ExecuteScalar (). ToString ();
DateTime jtdtm = DateTime. Parse (dtm );

Return jtdtm;
}

Call:

DateTime dt = oracleGetsysDate. sysDate (). Date;

XPO business class:

Public class TEST: XPLiteObject
{
String fDEPT_CODE;
[Key]
[Size (10)]
[DbType ("varchar2 (30)")] [Persistent ("Dept_code")] [DisplayName ("Department Code")]
Public string DEPT_CODE
{
Get {return fDEPT_CODE ;}
Set {SetPropertyValue ("DEPT_CODE", ref fDEPT_CODE, value );}
}
String fDEPT_NAME;
[Size (30)]
Public string DEPT_NAME
{
Get {return fDEPT_NAME ;}
Set {SetPropertyValue ("DEPT_NAME", ref fDEPT_NAME, value );}
}
DateTime fCREATEDATE;
Public DateTime CREATEDATE
{
Get {return fCREATEDATE ;}
Set {

SetPropertyValue ("CREATEDATE", ref fCREATEDATE, value );}
}
Public TEST (Session session): base (session ){}
Public TEST (): base (Session. DefaultSession ){}
Public override void AfterConstruction () {base. AfterConstruction ();}
Protected override void OnSaving ()
{
Base. OnSaving ();
If (! IsDeleted)
{
UnitOfWork uw = new UnitOfWork ();

If (fDEPT_CODE = null | fDEPT_CODE = "")
Throw new Exception ("the Department Code cannot be null. Saving failed! ");

}
}
Protected override void Spoil (bool disposing)
{
Base. Spoil (disposing );
}
}

Call XPO:

Try
{
DateTime dt = oracleGetsysDate. sysDate (). Date;
Dbserver. TEST test = new TEST ();
Test. DEPT_CODE = "123 ";
Test. DEPT_NAME = "Test2 ";
Test. CREATEDATE = dt;

Test. Save ();
// DateTime dt = oracleGetsysDate. sysDate ();
// This. textBox1.Text = dt. ToString (); // obtain the first column of the first row of the query table.
}
Catch (Exception ex)
{
MessageBox. Show (ex. Message, "prompt ");
}

The Preliminary Study of XPO is relatively simple.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.