C # Get the common code for MySQL data

Source: Internet
Author: User

1. Read

 PublicDataTable executedatatable (stringSQLString) {using(Mysqlconnection connection =Newmysqlconnection (connectionString)) {DataSet DS=NewDataSet ();Try{connection. Open (); Mysqlcommand cmd=NewMysqlcommand (SQLString, connection); Mysqldataadapter Command=Newmysqldataadapter (cmd); command. Fill (DS,"DS");}Catch(MySql.Data.MySqlClient.MySqlException ex) {Throw NewException (ex. Message);}returnDs. tables[0];}}

2. use SET Identity_insert to manually insert a number for the database self-increment field

    stringSqlstr ="SET identity_insert t1 on;"; Lists.                ADD (SQLSTR); Sqlstr="INSERT into T1 (ID, name) VALUES ("+i.tostring () +", '"+ i.tostring () +"');"; Lists.                ADD (SQLSTR); Sqlstr="set identity_insert t1 off;"; Lists.                ADD (SQLSTR); Da. Sqlceexecutenonquery (lists);

 Public void Sqlceexecutenonquery(List<string>Lists) { SqlCeConnectionConn= New SqlCeConnection(); SqlCeCommandComm= Null; Try {Conn.ConnectionString = Pdaconnectionlocstr;Conn.Open();Comm= New SqlCeCommand("",Conn); For (IntI= 0;I<Lists.Count;I++) {Comm.CommandText =Lists[I];Comm.ExecuteNonQuery ();  } } catch   (sqlceexception Ex { }  { Conn. Close  Conn. Dispose  Comm. Dispose} }          /span>                

3.mysql Data unix timestamp and C # datetime type Interchange

dangranusing System;usingSystem.Collections.Generic;usingSystem.Text;namespacewwframework.datetimes{/// <summary>    ///time-dependent functions/// </summary>     Public Static classFunction {/// <summary>        ///Convert a Unix timestamp to a datetime type time/// </summary>        /// <param name= "D" >Double Type number</param>        /// <returns>DateTime</returns>         Public StaticSystem.DateTime Convertintdatetime (Doubled) {System.DateTime time=System.DateTime.MinValue; System.DateTime StartTime= TimeZone.CurrentTimeZone.ToLocalTime (NewSystem.DateTime (1970,1,1)); time=Starttime.addseconds (d); returnTime ; }        /// <summary>        ///convert C # datetime format to UNIX timestamp format/// </summary>        /// <param name= "Time" >Time</param>        /// <returns>Double</returns>         Public Static DoubleConvertdatetimeint (System.DateTime time) {DoubleIntresult =0; System.DateTime StartTime= TimeZone.CurrentTimeZone.ToLocalTime (NewSystem.DateTime (1970,1,1)); Intresult= (Time-startTime).            TotalSeconds; returnIntresult; }     }}

C # Get the common code for MySQL data

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.