WinCE database Operation class

Source: Internet
Author: User

usingSystem;usingSystem.IO;usingSystem.Text;usingSystem.Data;usingSystem.Data.SqlServerCe;usingSystem.Collections;usingSystem.Windows.Forms;usingsystem.data.common;//explains that--wince database operations are similar to Windows, suggesting that some statements can be tested in the WinCE database. namespacecedb{/// <summary>    ///Database Operations Classes/// </summary>     Public Static classDbsqlserver {/// <summary>        ///Get a DataTable/// </summary>        /// <param name= "SQL" ></param>         Public StaticDataTable Getdt (stringSQL) {SqlCeConnection conn=NULL; Try{conn=NewSqlCeConnection ("Data Source = 3190.sdf"); Try{Conn.                Open (); }                Catch(Exception ex) {Throw; } sqlcecommand cmd=Conn.                CreateCommand (); Cmd.commandtext=SQL; SqlCeDataAdapter Ada=NewSqlCeDataAdapter (CMD); DataTable DTS=NewDataTable (); Ada.                Fill (dts); Ada.                Dispose (); Conn.                Close (); returnDTS; }            Catch            {                Throw; }            finally            {                if(NULL!=conn) Conn.            Close (); }        }        /// <summary>        ///get ExecuteScalar, which is the first row of values in the data/// </summary>        /// <param name= "SQL" ></param>         Public StaticObject Getexecutescalar (stringSQL) {SqlCeConnection conn=NULL; Try{conn=NewSqlCeConnection ("Data Source = 3190.sdf"); Try{Conn.            Open (); }            Catch            {                Throw NewNullReferenceException ("failed to connect to database"); } sqlcecommand cmd=Conn.            CreateCommand (); Cmd.commandtext=SQL; returncmd.         ExecuteScalar (); }          Catch(SqlCeException e) {Throw NewNullReferenceException ("Operation Database Failed"); }        finally          {            if(Conn. state = =ConnectionState.Open) Conn.         Close (); }         }               Public Static voidExecuteNonQuery (stringsql//Execute SQL statement, no return{SqlCeConnection conn=NULL; Try{conn=NewSqlCeConnection ("Data Source = 3190.sdf"); Try{Conn.            Open (); }            Catch            {                Throw NewNullReferenceException ("failed to connect to database"); } sqlcecommand cmd=Conn.            CreateCommand (); Cmd.commandtext=SQL; Cmd.         ExecuteNonQuery (); }          Catch(SqlCeException e) {Throw NewNullReferenceException ("Operation Database Failed"); }        finally          {            if(Conn. state = =ConnectionState.Open) Conn.         Close (); }        }    }}

WinCE database Operation class

Related Article

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.